Skip to content

uucore: format: Fix hexadecimal default format print #7631

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 3 commits into from
Apr 4, 2025

Conversation

drinkcat
Copy link
Contributor

@drinkcat drinkcat commented Apr 1, 2025

Fix 2 more printing issues. For now, we print like GNU coreutils on x86-64 does. I plan to write up a bit more about float precision handling (and how we are different from GNU coreutils, not just in printf, but also in seq), but I think I'll do that as a separate PR.


uucore: format: Fix hexadecimal default format print

The default hex format, on x86(-64) prints 15 digits after the
decimal point, but also trims trailing zeros, so it's not just
a simple default precision and a little bit of extra handling is
required.

Also add a bunch of tests.

Fixes #7364.

uucore: format: Use Option for Float precision

The default precision for float actually depends on the format.
It's usually 6, but it's architecture-specific for hexadecimal
floats.

Set the precision as an Option, so that:

  • We don't need to sprinkle 6 in callers
  • We can actually handle unspecified precision correctly in
    float printing (next change).

uucore: format: Fix hexadecimal uppercase print (again)

When '%A' format is specified, we also need to capitalize the
0x, i.e. 0XEP-3, not 0xEP-3.

drinkcat added 3 commits April 1, 2025 15:04
When '%A' format is specified, we also need to capitalize the
`0x`, i.e. `0XEP-3`, not `0xEP-3`.
The default precision for float actually depends on the format.
It's _usually_ 6, but it's architecture-specific for hexadecimal
floats.

Set the precision as an Option, so that:
 - We don't need to sprinkle `6` in callers
 - We can actually handle unspecified precision correctly in
   float printing (next change).
The default hex format, on x86(-64) prints 15 digits after the
decimal point, _but_ also trims trailing zeros, so it's not just
a simple default precision and a little bit of extra handling is
required.

Also add a bunch of tests.

Fixes uutils#7364.
@sylvestre sylvestre merged commit 295628a into uutils:main Apr 4, 2025
68 checks passed
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 is different from coreutils
2 participants