From 7f96e5640611db9ecb4a560ea5d922d4c5adc074 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Wed, 11 Oct 2023 00:29:00 +0800 Subject: [PATCH] Update --- parts/_share/basic_environment/float_info.hpp | 10 +++++----- parts/header_file/files/elc/_files/base_defs/math.hpp | 4 ++-- .../files/elc/resolve_global_name_conflicts | 9 ++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/parts/_share/basic_environment/float_info.hpp b/parts/_share/basic_environment/float_info.hpp index 45149b8f..4aeff1f0 100644 --- a/parts/_share/basic_environment/float_info.hpp +++ b/parts/_share/basic_environment/float_info.hpp @@ -72,7 +72,7 @@ namespace float_infos{ static constexpr auto exponent_mask=uint16_t(0x7FFFu); //快速开方魔数 - static constexpr auto quick_invsqrt_magic_number=int16_t(0x59A8);//59a7 : 0.00187549, 59a8 : 0.0016386, 59a9 : 0.00181447 + static constexpr auto quick_invsqrt_magic_number=uint16_t(0xB350u);//59a7 : 0.00187549, 59a8 : 0.0016386, 59a9 : 0.00181447 }; struct float32_float_info{ //精确数部分的掩码 @@ -102,7 +102,7 @@ namespace float_infos{ static constexpr auto exponent_mask=uint32_t(0x7FFFFFFFu); //快速开方魔数 - static constexpr auto quick_invsqrt_magic_number=int32_t(0x5F375A86); + static constexpr auto quick_invsqrt_magic_number=uint32_t(0xBE6EB50Cu); }; struct float64_float_info{ //精确数部分的掩码 @@ -132,7 +132,7 @@ namespace float_infos{ static constexpr auto exponent_mask=uint64_t(0x7FFFFFFFFFFFFFFFu); //快速开方魔数 - static constexpr auto quick_invsqrt_magic_number=int64_t(0x5FE6EB50C7B537A9); + static constexpr auto quick_invsqrt_magic_number=uint64_t(0xBFCDD6A18F6A6F52u); }; #if defined(ELC_BASE_ENV_HAS_INT128) struct float128_float_info{ @@ -163,7 +163,7 @@ namespace float_infos{ static constexpr auto exponent_mask=0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_u128; //快速开方魔数 - static constexpr auto quick_invsqrt_magic_number=-0x72FFC263BBFB20013FFAD486DF24B9B3_i128; + static constexpr auto quick_invsqrt_magic_number=0xB2E33F324820BFFD8005AD87D212C5B0_u128; }; #endif struct bfloat16_float_info{ @@ -194,7 +194,7 @@ namespace float_infos{ static constexpr auto exponent_mask=uint16_t(0x7FFFu); //快速开方魔数 - static constexpr auto quick_invsqrt_magic_number=int16_t(0x5F35);//5f34 : 0.0035338, 5f35 : 0.00163863, 5f36 : 0.00357427 + static constexpr auto quick_invsqrt_magic_number=uint16_t(0xBE6Au);//5f34 : 0.0035338, 5f35 : 0.00163863, 5f36 : 0.00357427 }; template diff --git a/parts/header_file/files/elc/_files/base_defs/math.hpp b/parts/header_file/files/elc/_files/base_defs/math.hpp index 664ab3fc..25d0f183 100644 --- a/parts/header_file/files/elc/_files/base_defs/math.hpp +++ b/parts/header_file/files/elc/_files/base_defs/math.hpp @@ -384,8 +384,8 @@ namespace math{ if constexpr(is_big_type) return quick_invsqrt(static_cast(v)); else{ - constexpr auto magic = basic_environment::float_infos::quick_invsqrt_magic_number; - return union_cast(magic-(union_cast(v)>>1)); + using namespace basic_environment::float_infos; + return union_cast((quick_invsqrt_magic_number - union_cast>(v))>>1); } return 2u/v; } diff --git a/parts/header_file/files/elc/resolve_global_name_conflicts b/parts/header_file/files/elc/resolve_global_name_conflicts index 09f993ab..eda8cc62 100644 --- a/parts/header_file/files/elc/resolve_global_name_conflicts +++ b/parts/header_file/files/elc/resolve_global_name_conflicts @@ -47,18 +47,25 @@ #define rand the_rand #endif - #if defined(_MSC_VER)//msvc上type_info也是全局内容 + #if defined(_MSC_VER) namespace elc::defs{ template constexpr auto&the_type_info=type_info; + templaterequires(has_epsilon) + [[nodiscard]]force_inline constexpr T the_sqrt(const T&v){return sqrt(v);} + template[[nodiscard]]force_inline constexpr auto the_sqrt(const T&v){return sqrt(v);} } namespace elc{ using defs::the_type_info; } namespace std{ typedef type_info the_type_info; + [[nodiscard]]float the_sqrt(const float&v){return sqrtf(v);} + [[nodiscard]]double the_sqrt(const double&v){return sqrt(v);} + [[nodiscard]]long double the_sqrt(const long double&v){return sqrtl(v);} } #define type_info the_type_info + #define sqrt the_sqrt #endif #if defined(_INC_MATH)//float_t namespace elc{