Skip to content

numfmt: fix rounding for small scaled values#12032

Merged
cakebaker merged 1 commit into
uutils:mainfrom
hayato0909:numfmt-fix-small-scaled-rounding
Apr 27, 2026
Merged

numfmt: fix rounding for small scaled values#12032
cakebaker merged 1 commit into
uutils:mainfrom
hayato0909:numfmt-fix-small-scaled-rounding

Conversation

@hayato0909
Copy link
Copy Markdown
Contributor

Summary

Fixes rounding for small scaled values when numfmt --to=si/iec/iec-i does not select a suffix.

In this case GNU numfmt appears to use display formatting rounding for the scaled value, while uutils was applying the configured rounding method directly. This caused cases like --to=si 0.4 and --to=iec --to-unit=689 701 to round away from GNU behavior.

Changes

  • Keep the existing --to=none rounding path unchanged.
  • Adjust the suffix-less --to=si/iec/iec-i path to match GNU display rounding behavior.
  • Add regression tests for small scaled values, --to-unit, and --format precision.

Test plan

  • cargo fmt
  • cargo test -p uu_numfmt
  • cargo test --test tests test_numfmt::test_to_unitless_small_values_use_display_rounding
  • cargo test --test tests test_numfmt::test_to_unit_with_unitless_small_value_uses_display_rounding
  • cargo test --test tests test_numfmt::test_format_with_precision_and_unitless_to_arg

Fixes #11938

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

GNU testsuite comparison:

Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.

@cakebaker cakebaker force-pushed the numfmt-fix-small-scaled-rounding branch from b7b5f85 to f0e1d70 Compare April 27, 2026 14:55
@cakebaker cakebaker merged commit 7d3a347 into uutils:main Apr 27, 2026
169 checks passed
@cakebaker
Copy link
Copy Markdown
Contributor

Thanks for your PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

numfmt: rounding of scaled values diverges from GNU for small fractionals and iec boundaries

2 participants