mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 17:26:51 +08:00
Removing dead code
This commit is contained in:
parent
cad8cfdf57
commit
192b271c12
@ -203,44 +203,6 @@ struct decimal {
|
||||
// Moves are allowed:
|
||||
decimal(decimal &&) = default;
|
||||
decimal &operator=(decimal &&other) = default;
|
||||
// Generates a mantissa by truncating to 19 digits.
|
||||
// This function should be reasonably fast.
|
||||
// Note that the user is responsible to ensure that digits are
|
||||
// initialized to zero when there are fewer than 19.
|
||||
inline uint64_t to_truncated_mantissa() {
|
||||
#if FASTFLOAT_IS_BIG_ENDIAN == 1
|
||||
uint64_t mantissa = 0;
|
||||
for (uint32_t i = 0; i < max_digit_without_overflow;
|
||||
i++) {
|
||||
mantissa = mantissa * 10 + digits[i]; // can be accelerated
|
||||
}
|
||||
return mantissa;
|
||||
#else
|
||||
uint64_t val;
|
||||
// 8 first digits
|
||||
::memcpy(&val, digits, sizeof(uint64_t));
|
||||
val = val * 2561 >> 8;
|
||||
val = (val & 0x00FF00FF00FF00FF) * 6553601 >> 16;
|
||||
uint64_t mantissa =
|
||||
uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32);
|
||||
// 8 more digits for a total of 16
|
||||
::memcpy(&val, digits + sizeof(uint64_t), sizeof(uint64_t));
|
||||
val = val * 2561 >> 8;
|
||||
val = (val & 0x00FF00FF00FF00FF) * 6553601 >> 16;
|
||||
uint32_t eight_digits_value =
|
||||
uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32);
|
||||
mantissa = 100000000 * mantissa + eight_digits_value;
|
||||
for (uint32_t i = 2 * sizeof(uint64_t); i < max_digit_without_overflow;
|
||||
i++) {
|
||||
mantissa = mantissa * 10 + digits[i]; // can be accelerated
|
||||
}
|
||||
return mantissa;
|
||||
#endif
|
||||
}
|
||||
// Generate an exponent matching to_truncated_mantissa()
|
||||
inline int32_t to_truncated_exponent() {
|
||||
return decimal_point - int32_t(max_digit_without_overflow);
|
||||
}
|
||||
};
|
||||
|
||||
constexpr static double powers_of_ten_double[] = {
|
||||
|
||||
@ -353,19 +353,6 @@ adjusted_mantissa compute_float(decimal &d) {
|
||||
template <typename binary>
|
||||
adjusted_mantissa parse_long_mantissa(const char *first, const char* last) {
|
||||
decimal d = parse_decimal(first, last);
|
||||
// In some cases we can get lucky and looking at only the first 19 digits is enough.
|
||||
// Let us try that.
|
||||
const uint64_t mantissa = d.to_truncated_mantissa();
|
||||
const int64_t exponent = d.to_truncated_exponent();
|
||||
// credit: R. Oudompheng who first implemented this fast path (to my knowledge).
|
||||
// It is rough, but it does the job of accelerating the slow path since most
|
||||
// long streams of digits are determined after 19 digits.
|
||||
// Note that mantissa+1 cannot overflow since mantissa < 10**19 and so
|
||||
// mantissa+1 <= 10**19 < 2**64.
|
||||
adjusted_mantissa am1 = compute_float<binary>(exponent, mantissa);
|
||||
adjusted_mantissa am2 = compute_float<binary>(exponent, mantissa+1);
|
||||
// They must both agree and be both a successful result.
|
||||
if(( am1 == am2 ) && (am1.power2 >= 0)) { return am1; }
|
||||
return compute_float<binary>(d);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user