-
-
Notifications
You must be signed in to change notification settings - Fork 799
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
Add NumberInput.parseFloat()
#753
Comments
@pjfanning Please ensure that it is used for parsing floats to avoid 1ULP rounding error that happens with v2.13.2 |
@plokhotnyuk I think the jackson issue you describe is because in some cases jackson seems to use Double.parseDouble to parse floats and then later to cast that to a float and that seems to lead to the loss of precision with the "1.199999988079071" case. |
@plokhotnyuk is 1.2f actually a better answer than 1.999999f - it is actually closer to 1.199999988079071
|
Exact binary representation of
When fitting to 32-bit float the properly rounded binary value is:
That is You can use the following online calculator to check this: |
@cowtowncoder this code in ParserBase (jackson-core) may be contributing to the issue that @plokhotnyuk described with parsing
From my testing, it seems that casting doubles to floats may not get the same result as parsing the text representation directly with Float.parseFloat(String). |
I created #755 for the issue about 1.199999988079071 - I want to keep this issue for the original purpose of updating NumberInput to have a parseFloat(String) |
Hmm, I may be mistaken, but isn't float inaccurate/non-precise by default, are we absolutely sure the algorithm doesn't go to that value as the closest possible match to the requested value? Is there any benefit in trying to make an inherent non precise number system precise? |
I need to go into this with more detail with @plokhotnyuk because I can't reproduce his issue and I'd like to move that discussion to #755 - this issue was originally about a small code refactor |
I think this issue specifically is resolved, so closing, but follow-up discussions -- which are related but not directly caused by this -- should proceed. Put another way: this just adds a method to call; coercions between float, double etc happen in different places in code (mostly |
For v2.14, NumberInput has become the main way to centralise the code for parsing numbers. One inconsistency is that Floats are still parsed using Float.parseFloat. Having a NumberInput.parseFloat that does that means we can change the implementation later to use the fast-double-parser or something similar. See #577
The text was updated successfully, but these errors were encountered: