Make exponent threshold depend on representation (#3649)

This commit is contained in:
Victor Zverovich
2025-01-26 11:51:56 -08:00
parent 9cf9f38ede
commit 52eeeb52a6
3 changed files with 22 additions and 10 deletions

View File

@@ -312,6 +312,7 @@ template <> struct numeric_limits<double_double> {
// is_iec559 is true for double-double in libstdc++.
static constexpr bool is_iec559 = true;
static constexpr int digits = 106;
static constexpr int digits10 = 33;
};
template <> struct is_floating_point<slow_float> : std::true_type {};
@@ -341,7 +342,7 @@ TEST(format_impl_test, write_dragon_even) {
auto s = std::string();
fmt::detail::write<char>(std::back_inserter(s), slow_float(33554450.0f), {});
// Specializing is_floating_point is broken in MSVC.
if (!FMT_MSC_VERSION) EXPECT_EQ(s, "33554450");
if (!FMT_MSC_VERSION) EXPECT_EQ(s, "3.355445e+07");
}
#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)

View File

@@ -1068,7 +1068,8 @@ TEST(format_test, precision) {
EXPECT_EQ(fmt::format("{:#.0f}", 123.0), "123.");
EXPECT_EQ(fmt::format("{:.02f}", 1.234), "1.23");
EXPECT_EQ(fmt::format("{:.1g}", 0.001), "0.001");
EXPECT_EQ(fmt::format("{}", 1019666432.0f), "1019666400");
EXPECT_EQ(fmt::format("{}", 123456789.0f), "1.2345679e+08");
EXPECT_EQ(fmt::format("{}", 1019666432.0f), "1.0196664e+09");
EXPECT_EQ(fmt::format("{:.0e}", 9.5), "1e+01");
EXPECT_EQ(fmt::format("{:.1e}", 1e-34), "1.0e-34");