From f233b56cdd20d4ec99bf8551f2c41e408ef987aa Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 12 Sep 2020 09:19:50 -0700 Subject: [PATCH] Don't generate insignificant digits --- include/fmt/format-inl.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index a2522b77..5f967aca 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1061,7 +1061,10 @@ void fallback_format(Double d, int num_digits, buffer& buf, int& exp10) { if (upper != &lower) *upper *= 10; } } - // Generate the given number of digits. + // Generate the given number of digits up to the maximum possible number of + // significant digits in a IEEE754 double. + const int max_double_digits = 767; + if (num_digits > max_double_digits) num_digits = max_double_digits; exp10 -= num_digits - 1; if (num_digits == 0) { buf.try_resize(1);