Minor cleaning.

This commit is contained in:
Daniel Lemire 2020-11-12 22:35:32 -05:00
parent 1b775cd9a7
commit e79741ede2
2 changed files with 7 additions and 2 deletions

View File

@ -241,6 +241,10 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n
answer.truncated = true;
answer.num_digits = max_digits;
}
// In very rare cases, we may have fewer than 19 digits, we want to be able to reliably
// assume that all digits up to max_digit_without_overflow have been initialized.
for(uint32_t i = answer.num_digits; i < max_digit_without_overflow; i++) { answer.digits[i] = 0; }
return answer;
}
} // namespace fast_float

View File

@ -149,9 +149,10 @@ struct decimal {
// Moves are allowed:
decimal(decimal &&) = default;
decimal &operator=(decimal &&other) = default;
// Generates a mantissa by truncating to 19 digits; this function assumes
// that num_digits >= 19 (the caller is responsible for the check).
// 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() {
uint64_t val;
// 8 first digits