Skip to content

numfmt: refuse a value too large to print when it has a suffix - #15672

Open
jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:numfmt-too-large-with-suffix
Open

jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:numfmt-too-large-with-suffix

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

A number read with a suffix is not checked against the size limit for printing, so numfmt prints a rounded float instead of failing:

$ numfmt --from=si 1Y
GNU 9.7:  numfmt: value too large to be printed: '1e+24' (consider using --to)   (exit 2)
uutils:   999999999999999983222784                                               (exit 0)

Same for 10E, 1Z, 1R, 1Q, --from=auto 1Zi, and with --format=%.1f. Numbers written out in full were already refused; a suffixed value takes the float path in transform_to, which had no check. It now gets the same one (value times 10^precision against 10^19) when there is no --to.

The message also follows GNU in two details: without a precision it is value too large to be printed: '1e+19' (it said value/precision ... '1e+19/0'), and the value is printed like %g, so 1 and 0 show as 1 and 0 instead of 1e+0 and 0e+0.

Two existing expectations change: test_format_precision_too_large_on_zero expected '0e+0/40' (GNU: '0/40'), and --format=%.65536f 1.5, added in #13514 to stop a panic, expected 2; GNU refuses it with '1.5/65536', and so does this branch, still without a panic.

New tests test_value_with_suffix_too_large_to_print and test_value_too_large_without_precision; they and the updated zero case fail on main. The numfmt tests pass (172), clippy is clean. 34 inputs around the limit (suffixes, negative values, --format precisions, --to-unit, --from-unit, --invalid=warn, fields, padding) give the same output and exit code as GNU 9.7.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 06:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.04 MB (-304 KB, -0.19%)

Significant per-binary changes:
  date     2.61 MB ->    2.30 MB  (-316 KB, -11.81%)

--from=si 1Y printed 999999999999999983222784, an f64 rounding of 10^24; GNU stops at 10^19 and exits 2, as numfmt already did for numbers without a suffix. The message names the precision only when there is one and prints the value like %g ('1/20', '0/40'), as GNU does.
@sylvestre
sylvestre force-pushed the numfmt-too-large-with-suffix branch from 7d90bc4 to 1c9e428 Compare October 25, 2026 12:55
Copilot AI balanced review requested due to automatic review settings October 25, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

This branch has not been deployed

No deployments
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.

2 participants