Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upFloat point reading is lossy. #120
Comments
miloyip
added this to the v1.0 Beta milestone
Sep 1, 2014
miloyip
added
the
bug
label
Sep 1, 2014
miloyip
self-assigned this
Sep 1, 2014
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
My 3¢:
|
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
Any suggestion? Using macro as parameter default value? |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
|
Today I have refactored Regarding to @pah 's comment
I have added an experiment with random generated
Since |
This comment has been minimized.
This comment has been minimized.
|
Nice work! Now only the "default parse flags" are missing, but this is a separate issue, I guess. |
miloyip
referenced this issue
Sep 6, 2014
Merged
Parse JSON number to double in full-precision. #137
This comment has been minimized.
This comment has been minimized.
|
For me, numerical correctness is more important than speed, but I do like the focus you have on performance. |
xpol commentedAug 28, 2014
The float point value
0.9868011474609375become0.9868011474609376.If it is a performance tradeoff, I think we should provide an option to user that prefers correctness over speed.