-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Float printing with incorrect rounding. #33185
Comments
This seems to be related to how we now use julia> round(22.89825, sigdigits=6)
22.8982 I'm not an expert on rounding or understand why this is rounding like it is; maybe @simonbyrne or @JeffreySarnoff know what's going on here? |
So "22.8983" is the right answer. We should try not to use |
..........so |
If 22.89825 were exactly representable as a binary float, the new behavior would be correct. Julia 1.2:
Julia 1.4.0-DEV.97
|
If I'm reading details of IEEE-754 right, the correct way is to treat the representable value as if it were the infinitely precise intended value. And with rounding nearest tie to even, the result in the 1.4-DEV would seem to be correct? But for comparison, in C#:
Produces 22.8983 |
Leaving aside that "what you want" will differ between users, this isn't guaranteed, as there are cases which also go the other way, e.g.
We probably should be more explicit in the docs that it may not handle near-tied values correctly (no matter how you define the "correct" behaviour). But my original point is that any printing code shouldn't be calling |
Looking at the Ryu code, it looks like the correct solution is to use |
Yes, round can get things wrong, which needs to be fixed, but also this should not use |
Alright, diving in on this now. |
…igits instead of using round function. Note the significant digits do not include leading/trailing zeros
Fix #33185 by rounding to 6 significant digits while printing float d…
It looks like there are still some cases where we aren't breaking ties correctly (these are actually broken in versions as well):
Note that
|
I was about to post something similar. That bug was fixed but a new one was introduced. The value "0.025621074" is being printed as "0.025621" and not "0.0256211" in the nightly. |
Just confirming that my tests pass on the nightly now. Thanks all! |
I can't say the cause, but one of my tests with respect to show() for a custom type has started breaking in the nightly Julia branch in Travis CI tests. 1.2 is fine.
The difference is in the rounding behavior for display of a floating point value using
This used to produce 22.8983. Now it produces 22.8982.
May be linked to switch from "Grisu" to "Ryu"? Don't know why that would be though. From commit 869090b
The text was updated successfully, but these errors were encountered: