@@ -230,6 +230,14 @@ struct is_supported_float_type
230
230
> {
231
231
};
232
232
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
+
233
241
template <typename T> struct is_supported_integer_type : std::is_integral<T> {};
234
242
235
243
template <typename UC>
@@ -413,8 +421,7 @@ constexpr uint64_t constant_55555 = 5 * 5 * 5 * 5 * 5;
413
421
template <typename T, typename U = void > struct binary_format_lookup_tables ;
414
422
415
423
template <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>;
418
425
419
426
static inline constexpr int mantissa_explicit_bits ();
420
427
static inline constexpr int minimum_exponent ();
@@ -694,11 +701,10 @@ binary_format<double>::hidden_bit_mask() {
694
701
template <typename T>
695
702
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
696
703
to_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 ();
702
708
#if FASTFLOAT_HAS_BIT_CAST
703
709
value = std::bit_cast<T>(word);
704
710
#else
@@ -841,6 +847,21 @@ fastfloat_really_inline constexpr uint64_t min_safe_u64(int base) {
841
847
return int_luts<>::min_safe_u64[base - 2 ];
842
848
}
843
849
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
+
844
865
constexpr chars_format operator ~(chars_format rhs) noexcept {
845
866
using int_type = std::underlying_type<chars_format>::type;
846
867
return static_cast <chars_format>(~static_cast <int_type>(rhs));
0 commit comments