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

uucore:format:fix floating-point representation #7034

Merged

Conversation

alexs-sh
Copy link
Contributor

@alexs-sh alexs-sh commented Dec 30, 2024

This PR resolves issues with exponent calculation and usage, ensuring more accurate formatting:

  • Exponent for negative values can differ from 0
  • Switching to decimal mode now follows the P > X ≥ −4 rule

Fixes #7031

Before

cargo run -- printf "%g" -0.1171875
-0.11719          
 
cargo run -- printf "%g"  -0.00001
-0.00001              

After

cargo run -- printf "%g" -0.1171875
-0.117188        
          
cargo run -- printf "%g"  -0.00001
-1e-05                                

Expected

printf "%g" -0.1171875
-0.117188  

printf "%g" -0.00001
-1e-05                               

@alexs-sh alexs-sh force-pushed the uucore-fix-fp-general-format-output branch from f4b248e to 79847b8 Compare December 30, 2024 22:40
Copy link

GNU testsuite comparison:

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

@alexs-sh alexs-sh force-pushed the uucore-fix-fp-general-format-output branch 2 times, most recently from 55da066 to dfd1621 Compare December 31, 2024 08:43
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/seq/seq is no longer failing!

@alexs-sh alexs-sh force-pushed the uucore-fix-fp-general-format-output branch from dfd1621 to 356da0e Compare December 31, 2024 10:33
Copy link

GNU testsuite comparison:

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

@alexs-sh alexs-sh changed the title uucore:format:fix floating-point rounding uucore:format:fix floating-point representation Dec 31, 2024
This change resolves issues with exponent calculation and usage,
ensuring more accurate formatting:

- Exponent for negative values can differ from 0
- Switching to decimal mode now follows the P > X ≥ −4 rule
@alexs-sh alexs-sh force-pushed the uucore-fix-fp-general-format-output branch from 356da0e to 4c330d4 Compare December 31, 2024 12:19
Copy link

GNU testsuite comparison:

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

@sylvestre
Copy link
Contributor

excellent, thanks :)

@sylvestre sylvestre merged commit 6d028cd into uutils:main Jan 1, 2025
63 checks passed
@alexs-sh
Copy link
Contributor Author

alexs-sh commented Jan 1, 2025

I'm glad to help :)

@alexs-sh alexs-sh deleted the uucore-fix-fp-general-format-output branch January 2, 2025 15:03
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:output doesn't match with GNU printf
2 participants