-
Notifications
You must be signed in to change notification settings - Fork 3.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 point reading is lossy. #120
Comments
I recently tried an approach in this branch.
More tests have been added and it can parse the numbers exactly (so with google test However, the downside is that, the backup process incur unnecessary overheads even for parsing integers. And also calling C++ It is now getting two questions:
Besides, another issue is that, with the exact solution, the lookup table in |
My 3¢:
|
To keep both options, possible implementations:
Seems 3 is more flexible and easier to test. I think that the function is quite difficult to be refactored... But I can try. I am not sure how to calculate maximum error analytically. I can try to get empirical result with random values. |
I think if I dislike (1) and I even more dislike code duplication. The "local variable" problem can be solved by a similar technique as done for the local copy of the stream: Have a small template class wrapped around the local variable and providing its operations, doing nothing in case of the fast-path-only solution. This way, the cost for the fast path is a single word on the stack. This should be acceptable. If we go for the template parameter, we'd need a way to set default parse flags globally to avoid cluttering the user code when choosing a non-default configuration. |
Any suggestion? Using macro as parameter default value? |
Yes, this could work as a simple solution: #ifndef RAPIDJSON_DEFAULT_PARSEFLAGS
#define RAPIDJSON_DEFAULT_PARSEFLAGS kParseNoFlags
#endif
enum ParseFlag {
kParseNoFlags = 0,
// ....
kParseDefaultFlags = RAPIDJSON_DEFAULT_PARSEFLAGS ... or something like this. |
Today I have refactored Regarding to @pah 's comment
I have added an experiment with random generated
Since |
Nice work! 👍 Now only the "default parse flags" are missing, but this is a separate issue, I guess. |
For me, numerical correctness is more important than speed, but I do like the focus you have on performance. |
Parse JSON number to double in full-precision with custom strtod. Fix #120
The float point value
0.9868011474609375
become0.9868011474609376
.If it is a performance tradeoff, I think we should provide an option to user that prefers correctness over speed.
The text was updated successfully, but these errors were encountered: