-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore zero-padding for non-finite floating points #2310
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1272,9 +1272,16 @@ TEST(format_test, format_nan) { | |||
double nan = std::numeric_limits<double>::quiet_NaN(); | ||||
EXPECT_EQ("nan", fmt::format("{}", nan)); | ||||
EXPECT_EQ("+nan", fmt::format("{:+}", nan)); | ||||
if (std::signbit(-nan)) | ||||
EXPECT_EQ(" +nan", fmt::format("{:+06}", nan)); | ||||
// '0'-fill option sets alignment to numeric overwriting any user-provided | ||||
// alignment | ||||
EXPECT_EQ(" +nan", fmt::format("{:^+06}", nan)); | ||||
EXPECT_EQ(" +nan", fmt::format("{:<+06}", nan)); | ||||
EXPECT_EQ(" +nan", fmt::format("{:>+06}", nan)); | ||||
if (std::signbit(-nan)) { | ||||
EXPECT_EQ("-nan", fmt::format("{}", -nan)); | ||||
else | ||||
EXPECT_EQ(" -nan", fmt::format("{:+06}", -nan)); | ||||
} else | ||||
fmt::print("Warning: compiler doesn't handle negative NaN correctly"); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please wrap the else statement in {} for consistency with if: } else {
fmt::print("Warning: compiler doesn't handle negative NaN correctly");
} |
||||
EXPECT_EQ(" nan", fmt::format("{: }", nan)); | ||||
EXPECT_EQ("NAN", fmt::format("{:F}", nan)); | ||||
|
@@ -1288,6 +1295,13 @@ TEST(format_test, format_infinity) { | |||
EXPECT_EQ("inf", fmt::format("{}", inf)); | ||||
EXPECT_EQ("+inf", fmt::format("{:+}", inf)); | ||||
EXPECT_EQ("-inf", fmt::format("{}", -inf)); | ||||
EXPECT_EQ(" +inf", fmt::format("{:+06}", inf)); | ||||
EXPECT_EQ(" -inf", fmt::format("{:+06}", -inf)); | ||||
// '0'-fill option sets alignment to numeric overwriting any user-provided | ||||
// alignment | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the desired behavior? Currently we lose the originally provided alignment because it seems to get replaced by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we should preserve the original alignment. I think it can be dome by changing Line 1950 in ca46637
to something like if (specs_.align == align::none) specs_.align = align::numeric; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that works! |
||||
EXPECT_EQ(" +inf", fmt::format("{:^+06}", inf)); | ||||
EXPECT_EQ(" +inf", fmt::format("{:<+06}", inf)); | ||||
EXPECT_EQ(" +inf", fmt::format("{:>+06}", inf)); | ||||
EXPECT_EQ(" inf", fmt::format("{: }", inf)); | ||||
EXPECT_EQ("INF", fmt::format("{:F}", inf)); | ||||
EXPECT_EQ("inf ", fmt::format("{:<7}", inf)); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please make this a proper sentence:
// Replace '0'-padding with space for non-finite values.