Right-align inf and nan with a bare width - #4895
Conversation
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.
|
Overall looks good but some CI jobs failed to start and are in a weird state. Could you rebase to rerun them? |
|
Rebased. |
fallenmi
left a comment
There was a problem hiding this comment.
Approved at exact head 7449a2b after independent validation.
I reproduced the bug on base/current main e27cc20: a bare width left-aligns nan and inf, unlike finite numeric values. The same seven-case oracle passes on this head, covering NaN, positive and negative infinity, explicit left and center alignment, zero-fill normalization, and finite-value parity. The full format-test binary passes (139 tests) with AppleClang, and git diff --check is clean. The write_padded<Char, align::right> default is correctly overridden by explicit alignment.
Reviewed with OpenAI Codex.
|
@fallenmi, please don't spam the issues with AI-generated comments. |
|
Thanks for the fix! |
Fixes #4894.
The nonfinite path in
write_floattakes the string default alignment rather than the numeric one, soinfandnancome out left-aligned while finite values with the same spec come out right-aligned.After the change both are right-aligned, matching
std::formatand the documented default. An explicit alignment is unaffected.format-test.ccgains cases forinfandnanunder a bare width. The assertion next to them already expected the new string for a signed nonfinite, so it was passing for the wrong reason.