@@ -94,8 +94,8 @@ eisel_lemire(ExpandedFloat<T> init_num,
94
94
uint32_t clz = cpp::countl_zero<UIntType>(mantissa);
95
95
mantissa <<= clz;
96
96
97
- uint32_t exp2 = static_cast < uint32_t >( exp10_to_exp2 (exp10)) +
98
- BITS_IN_MANTISSA + FloatProp::EXPONENT_BIAS - clz;
97
+ int32_t exp2 =
98
+ exp10_to_exp2 (exp10) + BITS_IN_MANTISSA + FloatProp::EXPONENT_BIAS - clz;
99
99
100
100
// Multiplication
101
101
const uint64_t *power_of_ten =
@@ -168,7 +168,7 @@ eisel_lemire(ExpandedFloat<T> init_num,
168
168
169
169
// The if block is equivalent to (but has fewer branches than):
170
170
// if exp2 <= 0 || exp2 >= 0x7FF { etc }
171
- if (exp2 - 1 >= (1 << FloatProp::EXPONENT_WIDTH) - 2 ) {
171
+ if (static_cast < uint32_t >( exp2) - 1 >= (1 << FloatProp::EXPONENT_WIDTH) - 2 ) {
172
172
return cpp::nullopt;
173
173
}
174
174
@@ -211,8 +211,8 @@ eisel_lemire<long double>(ExpandedFloat<long double> init_num,
211
211
uint32_t clz = cpp::countl_zero<UIntType>(mantissa);
212
212
mantissa <<= clz;
213
213
214
- uint32_t exp2 = static_cast < uint32_t >( exp10_to_exp2 (exp10)) +
215
- BITS_IN_MANTISSA + FloatProp::EXPONENT_BIAS - clz;
214
+ int32_t exp2 =
215
+ exp10_to_exp2 (exp10) + BITS_IN_MANTISSA + FloatProp::EXPONENT_BIAS - clz;
216
216
217
217
// Multiplication
218
218
const uint64_t *power_of_ten =
@@ -338,17 +338,16 @@ simple_decimal_conversion(const char *__restrict numStart,
338
338
// If the exponent is too large and can't be represented in this size of
339
339
// float, return inf.
340
340
if (hpd.get_decimal_point () > 0 &&
341
- exp10_to_exp2 (hpd.get_decimal_point () - 1 ) >
342
- static_cast <int64_t >(FloatProp::EXPONENT_BIAS)) {
343
- output.num = {0 , FPBits::MAX_EXPONENT};
341
+ exp10_to_exp2 (hpd.get_decimal_point () - 1 ) > FloatProp::EXPONENT_BIAS) {
342
+ output.num = {0 , fputil::FPBits<T>::MAX_EXPONENT};
344
343
output.error = ERANGE;
345
344
return output;
346
345
}
347
346
// If the exponent is too small even for a subnormal, return 0.
348
347
if (hpd.get_decimal_point () < 0 &&
349
348
exp10_to_exp2 (-hpd.get_decimal_point ()) >
350
- static_cast < int64_t > (FloatProp::EXPONENT_BIAS +
351
- FloatProp::MANTISSA_WIDTH)) {
349
+ (FloatProp::EXPONENT_BIAS +
350
+ static_cast < int32_t >( FloatProp::MANTISSA_WIDTH) )) {
352
351
output.num = {0 , 0 };
353
352
output.error = ERANGE;
354
353
return output;
@@ -607,7 +606,7 @@ clinger_fast_path(ExpandedFloat<T> init_num,
607
606
// log10(2^(exponent bias)).
608
607
// The generic approximation uses the fact that log10(2^x) ~= x/3
609
608
template <typename T> constexpr int32_t get_upper_bound () {
610
- return static_cast < int32_t >( fputil::FloatProperties<T>::EXPONENT_BIAS) / 3 ;
609
+ return fputil::FloatProperties<T>::EXPONENT_BIAS / 3 ;
611
610
}
612
611
613
612
template <> constexpr int32_t get_upper_bound<float >() { return 39 ; }
@@ -623,9 +622,9 @@ template <> constexpr int32_t get_upper_bound<double>() { return 309; }
623
622
// other out, and subnormal numbers allow for the result to be at the very low
624
623
// end of the final mantissa.
625
624
template <typename T> constexpr int32_t get_lower_bound () {
626
- return -(static_cast < int32_t > (fputil::FloatProperties<T>::EXPONENT_BIAS +
627
- fputil::FloatProperties<T>::MANTISSA_WIDTH +
628
- (sizeof (T) * 8 )) /
625
+ return -((fputil::FloatProperties<T>::EXPONENT_BIAS +
626
+ static_cast < int32_t >( fputil::FloatProperties<T>::MANTISSA_WIDTH +
627
+ (sizeof (T) * 8 ) )) /
629
628
3 );
630
629
}
631
630
0 commit comments