-
Notifications
You must be signed in to change notification settings - Fork 573
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
Round trip floats #128
Comments
I'm not sure the conclusion that the issue is with parsing is entirely correct (although there do seem to be problems in that area as well), since this test fails in the
|
@Mark-Simulacrum the f64 that is closest to 17.922589369123899 is identical to the f64 that is closest to 17.922589369123898, so dtoa (grisu2) is correct here. assert_eq!(17.922589369123898, 17.922589369123899); As I wrote:
|
In the extreme, you probably wouldn't expect this test to pass: test_write(17.92258936912389800000000000000001f64, "17.92258936912389800000000000000001"); |
Hmm, I wonder how Javascript's JSON.parse/JSON.stringify deal with this. |
@Mark-Simulacrum using f64 you cannot have both of these return "the expected": JSON.stringify(JSON.parse('{ "test": 17.922589369123898 }'))
JSON.stringify(JSON.parse('{ "test": 17.922589369123899 }')) because those are the same f64. |
Actually that is a good requirement. That is what this issue is asking for. That is what grisu2 guarantees should work if your parsing is good. This issue is for making our parsing good. The JS code you gave is a different (not good) requirement of |
Okay. Well, I'd be glad to help out, but I'm not sure where to start--or if you'd even like help :). |
We would love help as always! The number-parsing code starts here: de.rs#L224. Currently if it sees something like |
I've started looking into it, but haven't had any luck yet. I don't want to block anyone else from working on it, especially since I probably won't have much luck with it--I'm not very proficient at debugging parsing/serializing code. My initial findings seem to point to |
Looks like RapidJSON does the same thing we do. Here is the cast and here is the division. |
Let's follow up with a value -> string -> value roundtripping quickcheck once this is implemented. #138 has most of the code. |
This is what V8 uses for parsing strings to floats. Supposedly this guarantees correct round tripping of IEEE floats. |
The test report added here was manually modified, so the mimumims, totals, etc. are not correct. This was done to shorten the test assertions and to get around an issue with string to double parsing in serde_json (serde-rs/json#128) that made assertions around the many-decimaled values unreliable.
… ranges. (#6) * Does some refactoring to make functions shorter. They are doing some funky mutable reference passing that we may want to eliminate in the future. * Switches from Joinery to Itertools because Itertools was able to handle joining the result of flat_value_iterator, which is a FlatMap. * The test report added here was manually modified, so the minimums, totals, etc. are not correct. This was done to shorten the test assertions and to get around an issue with string to double parsing in serde_json (serde-rs/json#128) that made assertions around the many-decimaled values unreliable.
can we have the option to parse into some kind of decimal type? (as in, base 10 floating point) |
Hi, I saw that Edit: Following more tests, I may be wrong and round-trip works. It would still be nice to have an update for this issue. |
The ryu crate is for printing floats to string, so it wouldn't help with the parsing side which is where loss of accuracy happens. I am closing this issue and will open a new issue to hopefully make it clear that the remaining work is about parsing. |
Ideally this test would pass.
On the printing side grisu2 guarantees that the f64 closest to the string representation is identical to the original input, so the inaccuracy is somewhere on the parsing side.
The text was updated successfully, but these errors were encountered: