@@ -44,7 +44,8 @@ int32_t scientific_exponent(parsed_number_string& num) noexcept {
44
44
45
45
// this converts a native floating-point number to an extended-precision float.
46
46
template <typename T>
47
- fastfloat_really_inline adjusted_mantissa to_extended (T value) noexcept {
47
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
48
+ adjusted_mantissa to_extended (T value) noexcept {
48
49
using equiv_uint = typename binary_format<T>::equiv_uint;
49
50
constexpr equiv_uint exponent_mask = binary_format<T>::exponent_mask ();
50
51
constexpr equiv_uint mantissa_mask = binary_format<T>::mantissa_mask ();
@@ -53,7 +54,11 @@ fastfloat_really_inline adjusted_mantissa to_extended(T value) noexcept {
53
54
adjusted_mantissa am;
54
55
int32_t bias = binary_format<T>::mantissa_explicit_bits () - binary_format<T>::minimum_exponent ();
55
56
equiv_uint bits;
57
+ #if FASTFLOAT_HAS_BIT_CAST
58
+ bits = std::bit_cast<equiv_uint>(value);
59
+ #else
56
60
::memcpy (&bits, &value, sizeof (T));
61
+ #endif
57
62
if ((bits & exponent_mask) == 0 ) {
58
63
// denormal
59
64
am.power2 = 1 - bias;
@@ -72,7 +77,8 @@ fastfloat_really_inline adjusted_mantissa to_extended(T value) noexcept {
72
77
// we are given a native float that represents b, so we need to adjust it
73
78
// halfway between b and b+u.
74
79
template <typename T>
75
- fastfloat_really_inline adjusted_mantissa to_extended_halfway (T value) noexcept {
80
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
81
+ adjusted_mantissa to_extended_halfway (T value) noexcept {
76
82
adjusted_mantissa am = to_extended (value);
77
83
am.mantissa <<= 1 ;
78
84
am.mantissa += 1 ;
@@ -148,9 +154,10 @@ void round_down(adjusted_mantissa& am, int32_t shift) noexcept {
148
154
am.power2 += shift;
149
155
}
150
156
151
- fastfloat_really_inline void skip_zeros (const char *& first, const char * last) noexcept {
157
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
158
+ void skip_zeros (const char *& first, const char * last) noexcept {
152
159
uint64_t val;
153
- while (std::distance (first, last) >= 8 ) {
160
+ while (! cpp20_and_in_constexpr () && std::distance (first, last) >= 8 ) {
154
161
::memcpy (&val, first, sizeof (uint64_t ));
155
162
if (val != 0x3030303030303030 ) {
156
163
break ;
@@ -167,10 +174,11 @@ fastfloat_really_inline void skip_zeros(const char*& first, const char* last) no
167
174
168
175
// determine if any non-zero digits were truncated.
169
176
// all characters must be valid digits.
170
- fastfloat_really_inline bool is_truncated (const char * first, const char * last) noexcept {
177
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
178
+ bool is_truncated (const char * first, const char * last) noexcept {
171
179
// do 8-bit optimizations, can just compare to 8 literal 0s.
172
180
uint64_t val;
173
- while (std::distance (first, last) >= 8 ) {
181
+ while (! cpp20_and_in_constexpr () && std::distance (first, last) >= 8 ) {
174
182
::memcpy (&val, first, sizeof (uint64_t ));
175
183
if (val != 0x3030303030303030 ) {
176
184
return true ;
@@ -186,11 +194,12 @@ fastfloat_really_inline bool is_truncated(const char* first, const char* last) n
186
194
return false ;
187
195
}
188
196
189
- fastfloat_really_inline bool is_truncated (byte_span s) noexcept {
197
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
198
+ bool is_truncated (byte_span s) noexcept {
190
199
return is_truncated (s.ptr , s.ptr + s.len ());
191
200
}
192
201
193
- fastfloat_really_inline
202
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
194
203
void parse_eight_digits (const char *& p, limb& value, size_t & counter, size_t & count) noexcept {
195
204
value = value * 100000000 + parse_eight_digits_unrolled (p);
196
205
p += 8 ;
@@ -206,21 +215,23 @@ void parse_one_digit(const char*& p, limb& value, size_t& counter, size_t& count
206
215
count++;
207
216
}
208
217
209
- fastfloat_really_inline
218
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
210
219
void add_native (bigint& big, limb power, limb value) noexcept {
211
220
big.mul (power);
212
221
big.add (value);
213
222
}
214
223
215
- fastfloat_really_inline void round_up_bigint (bigint& big, size_t & count) noexcept {
224
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20
225
+ void round_up_bigint (bigint& big, size_t & count) noexcept {
216
226
// need to round-up the digits, but need to avoid rounding
217
227
// ....9999 to ...10000, which could cause a false halfway point.
218
228
add_native (big, 10 , 1 );
219
229
count++;
220
230
}
221
231
222
232
// parse the significant digits into a big integer
223
- inline void parse_mantissa (bigint& result, parsed_number_string& num, size_t max_digits, size_t & digits) noexcept {
233
+ inline FASTFLOAT_CONSTEXPR20
234
+ void parse_mantissa (bigint& result, parsed_number_string& num, size_t max_digits, size_t & digits) noexcept {
224
235
// try to minimize the number of big integer and scalar multiplication.
225
236
// therefore, try to parse 8 digits at a time, and multiply by the largest
226
237
// scalar value (9 or 19 digits) for each step.
@@ -300,7 +311,8 @@ inline void parse_mantissa(bigint& result, parsed_number_string& num, size_t max
300
311
}
301
312
302
313
template <typename T>
303
- inline adjusted_mantissa positive_digit_comp (bigint& bigmant, int32_t exponent) noexcept {
314
+ inline FASTFLOAT_CONSTEXPR20
315
+ adjusted_mantissa positive_digit_comp (bigint& bigmant, int32_t exponent) noexcept {
304
316
FASTFLOAT_ASSERT (bigmant.pow10 (uint32_t (exponent)));
305
317
adjusted_mantissa answer;
306
318
bool truncated;
@@ -323,7 +335,8 @@ inline adjusted_mantissa positive_digit_comp(bigint& bigmant, int32_t exponent)
323
335
// we then need to scale by `2^(f- e)`, and then the two significant digits
324
336
// are of the same magnitude.
325
337
template <typename T>
326
- inline adjusted_mantissa negative_digit_comp (bigint& bigmant, adjusted_mantissa am, int32_t exponent) noexcept {
338
+ inline FASTFLOAT_CONSTEXPR20
339
+ adjusted_mantissa negative_digit_comp (bigint& bigmant, adjusted_mantissa am, int32_t exponent) noexcept {
327
340
bigint& real_digits = bigmant;
328
341
int32_t real_exp = exponent;
329
342
@@ -383,7 +396,8 @@ inline adjusted_mantissa negative_digit_comp(bigint& bigmant, adjusted_mantissa
383
396
// the actual digits. we then compare the big integer representations
384
397
// of both, and use that to direct rounding.
385
398
template <typename T>
386
- inline adjusted_mantissa digit_comp (parsed_number_string& num, adjusted_mantissa am) noexcept {
399
+ inline FASTFLOAT_CONSTEXPR20
400
+ adjusted_mantissa digit_comp (parsed_number_string& num, adjusted_mantissa am) noexcept {
387
401
// remove the invalid exponent bias
388
402
am.power2 -= invalid_am_bias;
389
403
0 commit comments