Skip to content

Show zero with the requested precision in standard notation - #729

Open
Lotion-3 wants to merge 1 commit into
haskell:masterfrom
Lotion-3:realfloat-zero-precision
Open

Lotion-3 wants to merge 1 commit into
haskell:masterfrom
Lotion-3:realfloat-zero-precision

Conversation

@Lotion-3

Copy link
Copy Markdown

Fixes #641.

formatFloat and formatDouble with standard n show zero as 0.0 whatever n is, because specialStr renders it before the precision is applied:

>>> formatDouble (standard 0) 0      -- showFFloat (Just 0) 0 "": "0"
"0.0"
>>> formatDouble (standard 3) (-0)   -- showFFloat (Just 3) (-0) "": "-0.000"
"-0.0"

Zero now gets n digits after the decimal, like showFFloat; standardDefaultPrecision still gives 0.0. #637 fixes this as part of a larger overhaul; this is just the zero case, in case that's still a while off.

Tests: new cases in d2sStandard for 0.0 and -0.0 with precision 0, 2 and 3, for Double and Float. They fail on master.

formatFloat and formatDouble with standard n showed zero as 0.0 whatever n was, because specialStr renders it before the precision is applied. Zero now has n digits after the decimal, like showFFloat: "0" for standard 0, "0.00" for standard 2, and "-0.00" for negative zero.

Fixes haskell#641.
@Lotion-3
Lotion-3 force-pushed the realfloat-zero-precision branch from 0f0fdd5 to 9bd404d Compare November 24, 2026 17:38
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.

Positive and Negative Zero Print Incorrect Precision

1 participant