From da819feb74b5bbf10dfd458a611f4e68cabddd56 Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Tue, 3 Dec 2024 23:20:45 +0100 Subject: [PATCH] back to std::bit_cast --- include/fast_float/digit_comparison.h | 2 +- include/fast_float/float_common.h | 110 +++++++++++++++----------- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/include/fast_float/digit_comparison.h b/include/fast_float/digit_comparison.h index c870b14..d7ef3d9 100644 --- a/include/fast_float/digit_comparison.h +++ b/include/fast_float/digit_comparison.h @@ -72,7 +72,7 @@ to_extended(T value) noexcept { binary_format::minimum_exponent(); equiv_uint bits; #if FASTFLOAT_HAS_BIT_CAST - bits = bit_cast(value); + bits = std::bit_cast(value); #else ::memcpy(&bits, &value, sizeof(T)); #endif diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 9b59735..f819fee 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -260,6 +260,7 @@ struct is_supported_char_type > { }; +#if 0 union float_union { float f; uint32_t bits; @@ -341,6 +342,7 @@ fastfloat_really_inline constexpr std::bfloat16_t bit_cast(const uint16_t &u) { return fu.f; } #endif // __STDCPP_BFLOAT16_T__ +#endif // 0 // Compares two ASCII strings in a case insensitive manner. template @@ -519,25 +521,25 @@ template struct binary_format_lookup_tables; template struct binary_format : binary_format_lookup_tables { using equiv_uint = equiv_uint_t; - static inline constexpr int mantissa_explicit_bits(); - static inline constexpr int minimum_exponent(); - static inline constexpr int infinite_power(); - static inline constexpr int sign_index(); - static inline constexpr int + static constexpr int mantissa_explicit_bits(); + static constexpr int minimum_exponent(); + static constexpr int infinite_power(); + static constexpr int sign_index(); + static constexpr int min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST - static inline constexpr int max_exponent_fast_path(); - static inline constexpr int max_exponent_round_to_even(); - static inline constexpr int min_exponent_round_to_even(); - static inline constexpr uint64_t max_mantissa_fast_path(int64_t power); - static inline constexpr uint64_t + static constexpr int max_exponent_fast_path(); + static constexpr int max_exponent_round_to_even(); + static constexpr int min_exponent_round_to_even(); + static constexpr uint64_t max_mantissa_fast_path(int64_t power); + static constexpr uint64_t max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST - static inline constexpr int largest_power_of_ten(); - static inline constexpr int smallest_power_of_ten(); - static inline constexpr T exact_power_of_ten(int64_t power); - static inline constexpr size_t max_digits(); - static inline constexpr equiv_uint exponent_mask(); - static inline constexpr equiv_uint mantissa_mask(); - static inline constexpr equiv_uint hidden_bit_mask(); + static constexpr int largest_power_of_ten(); + static constexpr int smallest_power_of_ten(); + static constexpr T exact_power_of_ten(int64_t power); + static constexpr size_t max_digits(); + static constexpr equiv_uint exponent_mask(); + static constexpr equiv_uint mantissa_mask(); + static constexpr equiv_uint hidden_bit_mask(); }; template struct binary_format_lookup_tables { @@ -710,6 +712,11 @@ inline constexpr uint64_t binary_format::max_mantissa_fast_path() { return uint64_t(2) << mantissa_explicit_bits(); } +template <> +inline constexpr uint64_t binary_format::max_mantissa_fast_path() { + return uint64_t(2) << mantissa_explicit_bits(); +} + // credit: Jakub JelĂ­nek #ifdef __STDCPP_FLOAT16_T__ template struct binary_format_lookup_tables { @@ -768,6 +775,11 @@ inline constexpr int binary_format::max_exponent_fast_path() { return 4; } +template <> +inline constexpr int binary_format::mantissa_explicit_bits() { + return 10; +} + template <> inline constexpr uint64_t binary_format::max_mantissa_fast_path() { @@ -790,43 +802,43 @@ inline constexpr int binary_format::min_exponent_fast_path() { } template <> -constexpr int binary_format::mantissa_explicit_bits() { - return 10; -} - -template <> -constexpr int binary_format::max_exponent_round_to_even() { +inline constexpr int +binary_format::max_exponent_round_to_even() { return 5; } template <> -constexpr int binary_format::min_exponent_round_to_even() { +inline constexpr int +binary_format::min_exponent_round_to_even() { return -22; } -template <> constexpr int binary_format::minimum_exponent() { +template <> +inline constexpr int binary_format::minimum_exponent() { return -15; } -template <> constexpr int binary_format::infinite_power() { +template <> +inline constexpr int binary_format::infinite_power() { return 0x1F; } -template <> constexpr int binary_format::sign_index() { +template <> inline constexpr int binary_format::sign_index() { return 15; } template <> -constexpr int binary_format::largest_power_of_ten() { +inline constexpr int binary_format::largest_power_of_ten() { return 4; } template <> -constexpr int binary_format::smallest_power_of_ten() { +inline constexpr int binary_format::smallest_power_of_ten() { return -27; } -template <> constexpr size_t binary_format::max_digits() { +template <> +inline constexpr size_t binary_format::max_digits() { return 22; } @@ -887,6 +899,11 @@ binary_format::hidden_bit_mask() { return 0x0080; } +template <> +inline constexpr int binary_format::mantissa_explicit_bits() { + return 7; +} + template <> inline constexpr uint64_t binary_format::max_mantissa_fast_path() { @@ -909,43 +926,43 @@ inline constexpr int binary_format::min_exponent_fast_path() { } template <> -constexpr int binary_format::mantissa_explicit_bits() { - return 7; -} - -template <> -constexpr int binary_format::max_exponent_round_to_even() { +inline constexpr int +binary_format::max_exponent_round_to_even() { return 3; } template <> -constexpr int binary_format::min_exponent_round_to_even() { +inline constexpr int +binary_format::min_exponent_round_to_even() { return -24; } -template <> constexpr int binary_format::minimum_exponent() { +template <> +inline constexpr int binary_format::minimum_exponent() { return -127; } -template <> constexpr int binary_format::infinite_power() { +template <> +inline constexpr int binary_format::infinite_power() { return 0xFF; } -template <> constexpr int binary_format::sign_index() { +template <> inline constexpr int binary_format::sign_index() { return 15; } template <> -constexpr int binary_format::largest_power_of_ten() { +inline constexpr int binary_format::largest_power_of_ten() { return 38; } template <> -constexpr int binary_format::smallest_power_of_ten() { +inline constexpr int binary_format::smallest_power_of_ten() { return -60; } -template <> constexpr size_t binary_format::max_digits() { +template <> +inline constexpr size_t binary_format::max_digits() { return 98; } @@ -961,11 +978,6 @@ binary_format::max_mantissa_fast_path(int64_t power) { return (void)max_mantissa[0], max_mantissa[power]; } -template <> -inline constexpr uint64_t binary_format::max_mantissa_fast_path() { - return uint64_t(2) << mantissa_explicit_bits(); -} - template <> inline constexpr uint64_t binary_format::max_mantissa_fast_path(int64_t power) { @@ -1064,6 +1076,7 @@ to_float(bool negative, adjusted_mantissa am, T &value) { #endif } +#if 0 #ifdef __STDCPP_FLOAT16_T__ template <> fastfloat_really_inline void to_float(bool negative, @@ -1091,6 +1104,7 @@ fastfloat_really_inline void to_float(bool negative, } #endif // __STDCPP_BFLOAT16_T__ +#endif // 0 template struct space_lut { static constexpr bool value[] = {