Fix handling of very large precision in fixed format

This commit is contained in:
Victor Zverovich
2021-11-27 08:23:05 -08:00
parent 201971e293
commit c472a27818
2 changed files with 21 additions and 4 deletions

View File

@@ -2375,10 +2375,6 @@ FMT_HEADER_ONLY_CONSTEXPR20 int format_float(Float value, int precision,
const auto cached_pow = get_cached_power(
min_exp - (normalized.e + fp::num_significand_bits), cached_exp10);
normalized = normalized * cached_pow;
// Limit precision to the maximum possible number of significant digits in
// an IEEE754 double because we don't need to generate zeros.
const int max_double_digits = 767;
if (precision > max_double_digits) precision = max_double_digits;
gen_digits_handler handler{buf.data(), 0, precision, -cached_exp10, fixed};
if (grisu_gen_digits(normalized, 1, exp, handler) != digits::error &&
!is_constant_evaluated()) {
@@ -2394,6 +2390,10 @@ FMT_HEADER_ONLY_CONSTEXPR20 int format_float(Float value, int precision,
auto f = fp();
bool is_predecessor_closer =
specs.binary32 ? f.assign(static_cast<float>(value)) : f.assign(value);
// Limit precision to the maximum possible number of significant digits in
// an IEEE754 double because we don't need to generate zeros.
const int max_double_digits = 767;
if (precision > max_double_digits) precision = max_double_digits;
format_dragon(f, is_predecessor_closer, precision, buf, exp);
}
if (!fixed && !specs.showpoint) {