5
5
#include < cstdint>
6
6
#include < cassert>
7
7
#include < cstring>
8
+ #include < type_traits>
8
9
9
10
#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) \
10
11
|| defined(__amd64) || defined(__aarch64__) || defined(_M_ARM64) \
@@ -219,6 +220,8 @@ constexpr static float powers_of_ten_float[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5,
219
220
1e6 , 1e7 , 1e8 , 1e9 , 1e10 };
220
221
221
222
template <typename T> struct binary_format {
223
+ using equiv_uint = typename std::conditional<sizeof (T) == 4 , uint32_t , uint64_t >::type;
224
+
222
225
static inline constexpr int mantissa_explicit_bits ();
223
226
static inline constexpr int minimum_exponent ();
224
227
static inline constexpr int infinite_power ();
@@ -232,6 +235,9 @@ template <typename T> struct binary_format {
232
235
static inline constexpr int smallest_power_of_ten ();
233
236
static inline constexpr T exact_power_of_ten (int64_t power);
234
237
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 ();
235
241
};
236
242
237
243
template <> inline constexpr int binary_format<double >::mantissa_explicit_bits() {
@@ -339,6 +345,33 @@ template <> inline constexpr size_t binary_format<float>::max_digits() {
339
345
return 114 ;
340
346
}
341
347
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
+
342
375
template <typename T>
343
376
fastfloat_really_inline void to_float (bool negative, adjusted_mantissa am, T &value) {
344
377
uint64_t word = am.mantissa ;
0 commit comments