Skip to content

Fix seq output#5789

Merged
sylvestre merged 4 commits intouutils:mainfrom
samueltardieu:issue-5766
Jan 6, 2024
Merged

Fix seq output#5789
sylvestre merged 4 commits intouutils:mainfrom
samueltardieu:issue-5766

Conversation

@samueltardieu
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

I've added some tests as well

@sylvestre sylvestre merged commit a60c342 into uutils:main Jan 6, 2024
@github-actions
Copy link
Copy Markdown

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