-
Notifications
You must be signed in to change notification settings - Fork 105
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
Improvements to Double/Float conversion #121
Comments
Currently during parsing of float primitives there is a small error ~1ULP. I think it should be documented properly until "exact" parsing option (with precision ~0.5ULP) is not available. BTW, here is a post about the Rust project which tries to push the performance limits without losing in precision: |
I'm actually not aware of float examples which lead to wrong result. Do you have any? I saw that article but didn't have time to look into the code ;( Also, I find it interesting that Java does not behave as expected too: https://www.exploringbinary.com/java-doesnt-print-the-shortest-strings-that-round-trip/ |
The rounding error can be easy reproduced when parsing string representation of some double values.
The detailed explanation is in this comment |
Sure, but that will not trigger rounding error in DSL-JSON for floats. |
The following code can print lot of such numbers which are affected by rounding during parsing with DSL-JSON:
Below are samples from its output:
|
@zapov you can peek solutions for parsing and serialization of floats and decimals immediately from the jsoniter-scala-coreJVM sub-project: Feel free to translate all them into Java from mine or original code of authors of algorithms, as long as you adhere to the copyright notices for the writing and the code in authors' repositories and/or appropriate attribution is mentioned. Below are screenshots from results of benchmarks that compares those approaches used in jsoniter-scala with different JSON parsers for Scala on different JVMs. Throughput (ops/sec) of parsing for serialization of arrays with 128 floats or doubles is measured here: |
It would be nice to improve this, I "just" need to find some time to work on it :D |
Grisu3 works most of the time but it could be improved/replaced with a different faster algorithm.
Parsing doubles does not match Java algorithm in all cases (unless it's configured with Exact precision option; High precision probably gives the same numbers as Java - but not guaranteed).
Float uses double conversion which can lead to bit loss.
Look into suggested replacement for some of the problems: #120
The text was updated successfully, but these errors were encountered: