Fix fixed precision handling during rounding in long double

This commit is contained in:
Victor Zverovich 2023-08-07 13:56:53 -07:00
parent 3c1b3337de
commit d424862319
2 changed files with 3 additions and 1 deletions

View File

@ -3178,7 +3178,8 @@ FMT_CONSTEXPR20 inline void format_dragon(basic_fp<uint128_t> value,
}
if (buf[0] == overflow) {
buf[0] = '1';
++exp10;
if ((flags & dragon::fixed) != 0) buf.push_back('0');
else ++exp10;
}
return;
}

View File

@ -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));