Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Oct 10, 2023
1 parent 6de73aa commit 7f96e56
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 5 additions & 5 deletions parts/_share/basic_environment/float_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
//精确数部分的掩码
Expand Down Expand Up @@ -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{
//精确数部分的掩码
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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<basic_float_type T>
Expand Down
4 changes: 2 additions & 2 deletions parts/header_file/files/elc/_files/base_defs/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ namespace math{
if constexpr(is_big_type<T>)
return quick_invsqrt(static_cast<long double>(v));
else{
constexpr auto magic = basic_environment::float_infos::quick_invsqrt_magic_number<T>;
return union_cast<T>(magic-(union_cast<const decltype(magic)>(v)>>1));
using namespace basic_environment::float_infos;
return union_cast<T>((quick_invsqrt_magic_number<T> - union_cast<const data_type<T>>(v))>>1);
}
return 2u/v;
}
Expand Down
9 changes: 8 additions & 1 deletion parts/header_file/files/elc/resolve_global_name_conflicts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,25 @@
#define rand the_rand
#endif

#if defined(_MSC_VER)//msvc上type_info也是全局内容
#if defined(_MSC_VER)
namespace elc::defs{
template<class T>
constexpr auto&the_type_info=type_info<T>;
template<float_type T>requires(has_epsilon<T>)
[[nodiscard]]force_inline constexpr T the_sqrt(const T&v){return sqrt(v);}
template<integer_type T>[[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{
Expand Down

0 comments on commit 7f96e56

Please sign in to comment.