From 6b7bfed40c559c06d2a4e074427dbc24819bd447 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 3 Nov 2020 19:19:10 -0800 Subject: [PATCH] Fix fallback float formatter at assymetric bounds (#1976) --- include/fmt/format-inl.h | 2 +- test/format-test.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 9a5f85c2..9046de91 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -2332,7 +2332,7 @@ void fallback_format(Double d, int num_digits, bool binary32, buffer& buf, upper = &upper_store; } denominator.assign_pow10(exp10); - denominator <<= 1; + denominator <<= shift; } else if (exp10 < 0) { numerator.assign_pow10(-exp10); lower.assign(numerator); diff --git a/test/format-test.cc b/test/format-test.cc index 2f12bd15..1f9a208f 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1317,6 +1317,8 @@ TEST(FormatterTest, FormatDouble) { EXPECT_EQ(buffer, format("{:a}", -42.0)); safe_sprintf(buffer, "%A", -42.0); EXPECT_EQ(buffer, format("{:A}", -42.0)); + EXPECT_EQ("9223372036854775808.000000", + format("{:f}", 9223372036854775807.0)); } TEST(FormatterTest, PrecisionRounding) {