@@ -230,6 +230,14 @@ struct is_supported_float_type
230230 > {
231231};
232232
233+ template <typename T>
234+ using equiv_uint_t = typename std::conditional<
235+ sizeof (T) == 1 , uint8_t ,
236+ typename std::conditional<
237+ sizeof (T) == 2 , uint16_t ,
238+ typename std::conditional<sizeof (T) == 4 , uint32_t ,
239+ uint64_t >::type>::type>::type;
240+
233241template <typename T> struct is_supported_integer_type : std::is_integral<T> {};
234242
235243template <typename UC>
@@ -413,8 +421,7 @@ constexpr uint64_t constant_55555 = 5 * 5 * 5 * 5 * 5;
413421template <typename T, typename U = void > struct binary_format_lookup_tables ;
414422
415423template <typename T> struct binary_format : binary_format_lookup_tables<T> {
416- using equiv_uint =
417- typename std::conditional<sizeof (T) == 4 , uint32_t , uint64_t >::type;
424+ using equiv_uint = equiv_uint_t <T>;
418425
419426 static inline constexpr int mantissa_explicit_bits ();
420427 static inline constexpr int minimum_exponent ();
@@ -694,11 +701,10 @@ binary_format<double>::hidden_bit_mask() {
694701template <typename T>
695702fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
696703to_float (bool negative, adjusted_mantissa am, T &value) {
697- using fastfloat_uint = typename binary_format<T>::equiv_uint;
698- fastfloat_uint word = (fastfloat_uint)am.mantissa ;
699- word |= fastfloat_uint (am.power2 )
700- << binary_format<T>::mantissa_explicit_bits ();
701- word |= fastfloat_uint (negative) << binary_format<T>::sign_index ();
704+ using equiv_uint = equiv_uint_t <T>;
705+ equiv_uint word = equiv_uint (am.mantissa );
706+ word |= equiv_uint (am.power2 ) << binary_format<T>::mantissa_explicit_bits ();
707+ word |= equiv_uint (negative) << binary_format<T>::sign_index ();
702708#if FASTFLOAT_HAS_BIT_CAST
703709 value = std::bit_cast<T>(word);
704710#else
@@ -841,6 +847,21 @@ fastfloat_really_inline constexpr uint64_t min_safe_u64(int base) {
841847 return int_luts<>::min_safe_u64[base - 2 ];
842848}
843849
850+ static_assert (std::is_same<equiv_uint_t <double >, uint64_t >::value,
851+ " equiv_uint should be uint64_t for double" );
852+ static_assert (std::is_same<equiv_uint_t <float >, uint32_t >::value,
853+ " equiv_uint should be uint32_t for float" );
854+
855+ #ifdef __STDCPP_FLOAT64_T__
856+ static_assert (std::is_same<equiv_uint_t <std::float64_t >, uint64_t >::value,
857+ " equiv_uint should be uint64_t for std::float64_t" );
858+ #endif
859+
860+ #ifdef __STDCPP_FLOAT32_T__
861+ static_assert (std::is_same<equiv_uint_t <std::float32_t >, uint32_t >::value,
862+ " equiv_uint should be uint32_t for std::float32_t" );
863+ #endif
864+
844865constexpr chars_format operator ~(chars_format rhs) noexcept {
845866 using int_type = std::underlying_type<chars_format>::type;
846867 return static_cast <chars_format>(~static_cast <int_type>(rhs));
0 commit comments