55#include < cstdint>
66#include < cassert>
77#include < cstring>
8+ #include < type_traits>
89
910#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) \
1011 || defined (__amd64) || defined (__aarch64__) || defined (_M_ARM64) \
@@ -219,6 +220,8 @@ constexpr static float powers_of_ten_float[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5,
219220 1e6 , 1e7 , 1e8 , 1e9 , 1e10 };
220221
221222template <typename T> struct binary_format {
223+ using equiv_uint = typename std::conditional<sizeof (T) == 4 , uint32_t , uint64_t >::type;
224+
222225 static inline constexpr int mantissa_explicit_bits ();
223226 static inline constexpr int minimum_exponent ();
224227 static inline constexpr int infinite_power ();
@@ -232,6 +235,9 @@ template <typename T> struct binary_format {
232235 static inline constexpr int smallest_power_of_ten ();
233236 static inline constexpr T exact_power_of_ten (int64_t power);
234237 static inline constexpr size_t max_digits ();
238+ static inline constexpr equiv_uint exponent_mask ();
239+ static inline constexpr equiv_uint mantissa_mask ();
240+ static inline constexpr equiv_uint hidden_bit_mask ();
235241};
236242
237243template <> inline constexpr int binary_format<double >::mantissa_explicit_bits() {
@@ -339,6 +345,33 @@ template <> inline constexpr size_t binary_format<float>::max_digits() {
339345 return 114 ;
340346}
341347
348+ template <> inline constexpr binary_format<float >::equiv_uint
349+ binary_format<float >::exponent_mask() {
350+ return 0x7F800000 ;
351+ }
352+ template <> inline constexpr binary_format<double >::equiv_uint
353+ binary_format<double >::exponent_mask() {
354+ return 0x7FF0000000000000 ;
355+ }
356+
357+ template <> inline constexpr binary_format<float >::equiv_uint
358+ binary_format<float >::mantissa_mask() {
359+ return 0x007FFFFF ;
360+ }
361+ template <> inline constexpr binary_format<double >::equiv_uint
362+ binary_format<double >::mantissa_mask() {
363+ return 0x000FFFFFFFFFFFFF ;
364+ }
365+
366+ template <> inline constexpr binary_format<float >::equiv_uint
367+ binary_format<float >::hidden_bit_mask() {
368+ return 0x00800000 ;
369+ }
370+ template <> inline constexpr binary_format<double >::equiv_uint
371+ binary_format<double >::hidden_bit_mask() {
372+ return 0x0010000000000000 ;
373+ }
374+
342375template <typename T>
343376fastfloat_really_inline void to_float (bool negative, adjusted_mantissa am, T &value) {
344377 uint64_t word = am.mantissa ;
0 commit comments