Skip to content
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

printf: (partially) fix hex format: exponent is decimal, correctly print negative numbers #7365

Merged
merged 2 commits into from
Feb 28, 2025

Conversation

drinkcat
Copy link
Contributor

@drinkcat drinkcat commented Feb 26, 2025

uucore: format: Fix printing of floating hex exponents

Floating hex format is supposed to be [-]0xh.hhhp±d. Note that
the exponent is a decimal value, not an hex number: fix that.

Also, add basic tests for this format, while we're at it.

Test: cargo test --package uucore --all-features float

Fixes #7362.

uucore: format: Fix printing of negative floating hex

Negative numbers were not printed correctly with %a:

  • A leading - is expected.
  • The exponent mask was too wide (15 bits instead of 11)

This doesn't fix everything (see #7364), but at least the output is now somewhat correct.

Floating hex format is supposed to be `[-]0xh.hhhp±d`. Note that
the exponent is a decimal value, not an hex number: fix that.

Also, add basic tests for this format, while we're at it.

Test: `cargo test --package uucore --all-features float`

Fixes uutils#7362.
Negative numbers were not printed correctly with `%a`:
 - A leading `-` is expected.
 - The exponent mask was too wide (15 bits instead of 11)
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

Nice! I'm glad that you're fixing this, looks like I made some silly mistakes back when I wrote this 😄

@RenjiSann RenjiSann merged commit 5c29054 into uutils:main Feb 28, 2025
65 checks passed
@drinkcat drinkcat deleted the printf-float-hex-exponent branch February 28, 2025 14:55
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.

printf: %a output exponent is incorrect (should be decimal, not hexadecimal)
3 participants