mirror of
https://github.com/fastfloat/fast_float.git
synced 2026-01-01 03:12:18 +08:00
type usage fix and cleanup.
This commit is contained in:
parent
38d0ab3f8e
commit
147cf3b4c7
@ -17,7 +17,7 @@ namespace fast_float {
|
||||
// most significant bits and the low part corresponding to the least significant
|
||||
// bits.
|
||||
//
|
||||
template <limb_t bit_precision>
|
||||
template <am_bits_t bit_precision>
|
||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
|
||||
compute_product_approximation(am_pow_t q, am_mant_t w) noexcept {
|
||||
am_pow_t const index = 2 * (q - powers::smallest_power_of_five);
|
||||
@ -90,7 +90,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
|
||||
compute_error(am_pow_t q, am_mant_t w) noexcept {
|
||||
auto const lz = leading_zeroes(w);
|
||||
w <<= lz;
|
||||
value128 product =
|
||||
value128 const product =
|
||||
compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
|
||||
return compute_error_scaled<binary>(q, product.high, lz);
|
||||
}
|
||||
@ -201,7 +201,7 @@ compute_float(am_pow_t q, am_mant_t w) noexcept {
|
||||
answer.mantissa >>= 1;
|
||||
if (answer.mantissa >= (am_mant_t(2) << binary::mantissa_explicit_bits())) {
|
||||
answer.mantissa = (am_mant_t(1) << binary::mantissa_explicit_bits());
|
||||
++answer.power2; // undo previous addition
|
||||
++answer.power2; // undo previous line addition
|
||||
}
|
||||
|
||||
// Check if we have infinity after computation
|
||||
@ -210,6 +210,7 @@ compute_float(am_pow_t q, am_mant_t w) noexcept {
|
||||
answer.power2 = binary::infinite_power();
|
||||
answer.mantissa = 0;
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ to_extended(T const value) noexcept {
|
||||
constexpr am_pow_t bias = binary_format<T>::mantissa_explicit_bits() -
|
||||
binary_format<T>::minimum_exponent();
|
||||
|
||||
auto const bits = bit_cast<equiv_uint, T>(value);
|
||||
auto const bits = bit_cast<equiv_uint>(value);
|
||||
|
||||
if ((bits & exponent_mask) == 0) {
|
||||
// denormal
|
||||
|
||||
@ -120,27 +120,6 @@ using parse_options = parse_options_t<char>;
|
||||
|
||||
} // namespace fast_float
|
||||
|
||||
#if FASTFLOAT_HAS_BIT_CAST
|
||||
#include <bit>
|
||||
#endif
|
||||
|
||||
namespace fast_float {
|
||||
template <typename To, typename From>
|
||||
FASTFLOAT_CONSTEXPR20 To bit_cast(const From &from) noexcept {
|
||||
#if FASTFLOAT_HAS_BIT_CAST
|
||||
return std::bit_cast<To>(from);
|
||||
#else
|
||||
// Implementation of std::bit_cast for pre-C++20.
|
||||
static_assert(sizeof(To) == sizeof(From),
|
||||
"bit_cast requires source and destination to be the same size");
|
||||
auto to = To();
|
||||
// The cast suppresses a bogus -Wclass-memaccess on GCC.
|
||||
std::memcpy(static_cast<void *>(&to), &from, sizeof(to));
|
||||
return to;
|
||||
#endif
|
||||
}
|
||||
} // namespace fast_float
|
||||
|
||||
#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
|
||||
defined(__amd64) || defined(__aarch64__) || defined(_M_ARM64) || \
|
||||
defined(__MINGW64__) || defined(__s390x__) || \
|
||||
@ -269,7 +248,25 @@ FASTFLOAT_CONSTEXPR20 To bit_cast(const From &from) noexcept {
|
||||
#define FASTFLOAT_ENABLE_IF(...) \
|
||||
typename std::enable_if<(__VA_ARGS__), int>::type
|
||||
|
||||
#if FASTFLOAT_HAS_BIT_CAST
|
||||
#include <bit>
|
||||
#endif
|
||||
|
||||
namespace fast_float {
|
||||
template <typename To, typename From>
|
||||
constexpr fastfloat_really_inline To bit_cast(const From &from) noexcept {
|
||||
#if FASTFLOAT_HAS_BIT_CAST
|
||||
return std::bit_cast<To>(from);
|
||||
#else
|
||||
// Implementation of std::bit_cast for pre-C++20.
|
||||
static_assert(sizeof(To) == sizeof(From),
|
||||
"bit_cast requires source and destination to be the same size");
|
||||
auto to = To();
|
||||
// The cast suppresses a bogus -Wclass-memaccess on GCC.
|
||||
std::memcpy(static_cast<void *>(&to), &from, sizeof(to));
|
||||
return to;
|
||||
#endif
|
||||
}
|
||||
|
||||
fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() noexcept {
|
||||
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED
|
||||
@ -1124,7 +1121,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float(
|
||||
word =
|
||||
equiv_uint(word | equiv_uint(negative) << binary_format<T>::sign_index());
|
||||
#endif
|
||||
value = bit_cast<T, equiv_uint>(word);
|
||||
value = bit_cast<T>(word);
|
||||
}
|
||||
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user