mirror of
https://github.com/fmtlib/fmt.git
synced 2026-09-13 14:22:26 +08:00
Right-align inf and nan with a bare width (#4895)
fmt::format("{:6}", nan) gave "nan " where std::format and printf("%6f")
give " nan". write_nonfinite was the only numeric write path taking
write_padded's align::left default, so a width with no explicit align
left-aligned inf and nan while every finite value right-aligned. That
default only reaches align::none, leaving explicit <, > and ^ and the 0
flag unchanged.
This commit is contained in:
parent
e27cc20bd9
commit
e76a9520a3
@ -2402,12 +2402,11 @@ FMT_CONSTEXPR20 auto write_nonfinite(OutputIt out, bool isnan,
|
||||
const bool is_zero_fill =
|
||||
specs.fill_size() == 1 && specs.fill_unit<Char>() == '0';
|
||||
if (is_zero_fill) specs.set_fill(' ');
|
||||
return write_padded<Char>(out, specs, size,
|
||||
[=](reserve_iterator<OutputIt> it) {
|
||||
if (s != sign::none)
|
||||
*it++ = detail::getsign<Char>(s);
|
||||
return copy<Char>(str, str + str_size, it);
|
||||
});
|
||||
return write_padded<Char, align::right>(
|
||||
out, specs, size, [=](reserve_iterator<OutputIt> it) {
|
||||
if (s != sign::none) *it++ = detail::getsign<Char>(s);
|
||||
return copy<Char>(str, str + str_size, it);
|
||||
});
|
||||
}
|
||||
|
||||
// A decimal floating-point number significand * pow(10, exp).
|
||||
|
||||
@ -1622,6 +1622,7 @@ TEST(format_test, format_nan) {
|
||||
EXPECT_EQ(fmt::format("{:<7}", nan), "nan ");
|
||||
EXPECT_EQ(fmt::format("{:^7}", nan), " nan ");
|
||||
EXPECT_EQ(fmt::format("{:>7}", nan), " nan");
|
||||
EXPECT_EQ(fmt::format("{:7}", nan), " nan");
|
||||
}
|
||||
|
||||
TEST(format_test, format_infinity) {
|
||||
@ -1639,6 +1640,7 @@ TEST(format_test, format_infinity) {
|
||||
EXPECT_EQ(fmt::format("{:<7}", inf), "inf ");
|
||||
EXPECT_EQ(fmt::format("{:^7}", inf), " inf ");
|
||||
EXPECT_EQ(fmt::format("{:>7}", inf), " inf");
|
||||
EXPECT_EQ(fmt::format("{:7}", inf), " inf");
|
||||
}
|
||||
|
||||
TEST(format_test, format_long_double) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user