-
Notifications
You must be signed in to change notification settings - Fork 982
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
dom and OnDemand resolve double types to different results #2017
Comments
DOM seems to retain only 16 decimal places, and the 16th place is no longer exact |
In binary64, the decimal string 0.8825149536132812 is represented as 115673 * 2**(-17) which is 0.88251495361328125. You therefore have that |
Recommended reading:
The number parser in simdjson is state-of-the-art. It has been widely adopted: it is part of the Rust, Go, C# standard libraries. It is part of the GCC C++ standard library, and so forth. We always welcome bug reports, but you should assume that we are correct: we have not yet encountered a single bug regarding our number parsing. |
Note that this has nothing to do with simdjson. It is just standard C++. |
Thank you very much for your answer, now I understand the reason for this! But since my usage scenario needs to get unresolved values, I need to go for the ondemand method. |
Both DOM and ondemand give the same result. It is not possible that you get the double value 0.8825149536132812 in one case and a distinct double value 0.8825149536132813 in the second case. There are two good reasons for that:
Your code example does not do what you think it does. In one instance (ondemand), you are just printing out the content of the JSON string, and in the other (DOM), you are re-serializing a parsed number. |
Your title was... "dom and OnDemand resolve double types to different results" But it is not what your code does at all... Try the following code... padded_string paddedInputJson = R"({"score":0.8825149536132812})"_padded;
simdjson::dom::parser parser_dom;
simdjson::dom::element ele;
ele = parser_dom.parse(paddedInputJson);
double score_dom = ele["score"];
std::cout << " dom:" << score_dom << std::endl;
simdjson::ondemand::parser parser_ondemand;
simdjson::ondemand::value val;
val = parser_ondemand.iterate(paddedInputJson);
double score_ondemand = val["score"];
std::cout << "ondemand:" << score_ondemand << std::endl; |
Thank you very much for your guidance, I understand my mistake, thanks! |
When I parse 0.8825149536132812, dom gets an error in the result, Did I write something wrong? Thanks
code:
result:
The text was updated successfully, but these errors were encountered: