From d4248623196991b434b8cb7689affb83fd04aca2 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 7 Aug 2023 13:56:53 -0700 Subject: [PATCH] Fix fixed precision handling during rounding in long double --- include/fmt/format.h | 3 ++- test/format-test.cc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 6cd2c355..e5bd8b11 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3178,7 +3178,8 @@ FMT_CONSTEXPR20 inline void format_dragon(basic_fp value, } if (buf[0] == overflow) { buf[0] = '1'; - ++exp10; + if ((flags & dragon::fixed) != 0) buf.push_back('0'); + else ++exp10; } return; } diff --git a/test/format-test.cc b/test/format-test.cc index 52ac2caf..d148e743 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1472,6 +1472,7 @@ TEST(format_test, format_long_double) { EXPECT_EQ("0", fmt::format("{0:}", 0.0l)); EXPECT_EQ("0.000000", fmt::format("{0:f}", 0.0l)); EXPECT_EQ("0.0", fmt::format("{:.1f}", 0.000000001l)); + EXPECT_EQ("0.10", fmt::format("{:.2f}", 0.099l)); EXPECT_EQ("392.65", fmt::format("{0:}", 392.65l)); EXPECT_EQ("392.65", fmt::format("{0:g}", 392.65l)); EXPECT_EQ("392.65", fmt::format("{0:G}", 392.65l));