Skip to content

Fix seq output #5789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 6, 2024
Merged

Fix seq output #5789

merged 4 commits into from
Jan 6, 2024

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented Jan 5, 2024

The output of seq had two issues:

  • The default precision for %g was set to 0 instead of 6
  • Numbers whose integer part was larger than the precision and ended with zeroes (such as 10) where erroneously truncated by removing the trailing significant 0.

Fix #5766

Using `saturating_sub()` before converting to `usize` gives a wrong
feeling of security as it looks like it ensures that the value will
never go negative. However, since it is applied to `i32`, it can, and
converting it to `usize` would go horribly wrong anyway.

By following the code flow, `exponent` cannot be greater than
`precision`, or the `else` block would not have been taken.  A plain
subtraction will give the same result and will at least panic in debug
mode.
`seq --format %.2g 10 10` would display `1` because the precision would
not allow room for the decimal point, and the `0` in `10` would be
trimmed as an insignificant trailing `0`.

This has been fixed by only trimming trailing `0` in the presence of a
decimal point.
@samueltardieu
Copy link
Contributor Author

I've added some tests as well

@sylvestre sylvestre merged commit a60c342 into uutils:main Jan 6, 2024
Copy link

github-actions bot commented Jan 6, 2024

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/timeout/timeout is no longer failing!

@samueltardieu samueltardieu deleted the issue-5766 branch January 10, 2024 17:33
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.

seq: different output for seq --format=d%030g 12
2 participants