Skip to content

Commit

Permalink
Make hex float test more stable on different libc (fmtlib#3762)
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <[email protected]>
  • Loading branch information
phprus authored and happymonkey1 committed Apr 6, 2024
1 parent a07b1ee commit 76297b6
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1361,14 +1361,11 @@ TEST(format_test, format_double) {
EXPECT_EQ(fmt::format("{0:e}", 392.65), "3.926500e+02");
EXPECT_EQ(fmt::format("{0:E}", 392.65), "3.926500E+02");
EXPECT_EQ(fmt::format("{0:+010.4g}", 392.65), "+0000392.6");
char buffer[buffer_size];

#if FMT_CPLUSPLUS >= 201703L
double xd = 0x1.ffffffffffp+2;
safe_sprintf(buffer, "%.*a", 10, xd);
EXPECT_EQ(fmt::format("{:.10a}", xd), buffer);
safe_sprintf(buffer, "%.*a", 9, xd);
EXPECT_EQ(fmt::format("{:.9a}", xd), buffer);
EXPECT_EQ(fmt::format("{:.10a}", xd), "0x1.ffffffffffp+2");
EXPECT_EQ(fmt::format("{:.9a}", xd), "0x2.000000000p+2");

if (std::numeric_limits<long double>::digits == 64) {
auto ld = 0xf.ffffffffffp-3l;
Expand All @@ -1384,8 +1381,7 @@ TEST(format_test, format_double) {
EXPECT_EQ(fmt::format("{:#a}", d), "0x1.p-1022");

d = (std::numeric_limits<double>::max)();
safe_sprintf(buffer, "%a", d);
EXPECT_EQ(fmt::format("{:a}", d), buffer);
EXPECT_EQ(fmt::format("{:a}", d), "0x1.fffffffffffffp+1023");

d = std::numeric_limits<double>::denorm_min();
EXPECT_EQ(fmt::format("{:a}", d), "0x0.0000000000001p-1022");
Expand All @@ -1402,8 +1398,7 @@ TEST(format_test, format_double) {
EXPECT_EQ(fmt::format("{:a}", ld), "0x0.000000000000001p-16382");
}

safe_sprintf(buffer, "%.*a", 10, 4.2);
EXPECT_EQ(fmt::format("{:.10a}", 4.2), buffer);
EXPECT_EQ(fmt::format("{:.10a}", 4.2), "0x1.0ccccccccdp+2");

EXPECT_EQ(fmt::format("{:a}", -42.0), "-0x1.5p+5");
EXPECT_EQ(fmt::format("{:A}", -42.0), "-0X1.5P+5");
Expand Down

0 comments on commit 76297b6

Please sign in to comment.