-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Handle infinity and NaN cases #70
Comments
Looking into what others do, it seems the ECMAScript 5.1 specification explicitly specifies stringifying +/- Infinity and NaN as null.
http://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3 Of course, 'the String null' is pleasantly ambiguous. In Chrome I see it's actually doing:
|
Hi @EricMCornelius, thanks for the note. I'll check it tonight. All the best, Niels |
- If an overflow occurs during parsing a number from a JSON text, an exception (std::out_of_range for the moment, to be replaced by a user-defined exception #244) is thrown so that the overflow is detected early and roundtripping is guaranteed. - NaN and INF floating-point values can be stored in a JSON value and are not replaced by null. That is, the basic_json class behaves like double in this regard (no exception occurs). However, NaN and INF are serialized to “null”. - Adjusted test cases appropriately.
This issue is fixed with 8feaf8d as follows:
Waiting for Travis to complete. Then this issue can be closed and the different semantics can be described in the wiki. |
http://en.cppreference.com/w/cpp/io/c/fprintf
snprintf will format infinity and nan doubles as Inf/Infinity or nan/nan(char_sequence) respectively. This can break the validity of a json.dump() document:
json/src/json.hpp
Line 2279 in 1580eee
You can check for infinity/nan w/ std::isinfinite/std::isnan - not sure what you'd like to actually do in those scenarios (some specific/configurable string representation?)
http://en.cppreference.com/w/cpp/numeric/math/isfinite
The text was updated successfully, but these errors were encountered: