Repository navigation
numfmt: print an unsigned zero when rounding a negative number to zero - #15682
Merged
Merged
Conversation
round_with_precision turns a small negative value into -0.0, and format_float prints the sign of a negative zero, so `-0.3` with `--round=up --format=%.0f` came out as `-0` (and `-0000` when zero-padded). Drop the sign of a zero produced by rounding on the plain path. The --to path keeps its existing `-0` output. Closes uutils#15661
xtqqczze
reviewed
Oct 23, 2026
| .stdout_is("0\n0.0"); | ||
| } | ||
|
|
||
| // https://github.com/uutils/coreutils/issues/15661 |
Collaborator
There was a problem hiding this comment.
remove the reference to the fixed issue from the diff
|
Binary size comparison: |
Contributor
|
Thanks for your PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15661
When
--round,--to-unitor a--formatprecision rounded a small negative number to zero, the plain (no--to) path kept the sign and printed-0,-0.0or-0000. GNU prints an unsigned zero there. The plain path informat.rsnow drops the sign when the rounded value is zero, so the four cases from the issue print0,0,00000and0.0.The
--topath is left alone.numfmt --to=si -- -0.4still prints-0, same as GNU, and there's already a test for it intest_numfmt_args. There are a couple of--tocases with--round=up/towards-zerothat still print a signed zero; I kept those out of this PR since they go through different code.I added the four cases from the issue to
tests/by-util/test_numfmt.rs. They fail without the fix andtest_numfmtpasses with it.cargo fmtandclippy -D warningsare clean. Tested on macOS only.This doesn't overlap with #15636 (that one changes
consider_suffixon the--topath).