-
-
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
nan number stored as null #388
Comments
This seems related to #329. |
You are right - I think it should be OK for Any thoughts on this? |
I don't know. |
The JSON standard does not provide a way to store all IEEE 754 doubles. Adding support would be an extension (a desirable one), which this library has a policy of not doing. It sucks that basic_json would store something (nan) that it would not serialize correctly (ie, that it would not round-trip), but making the double-constructor throw is even worse. Are there already cases where the serializer would throw such that serializing nan could throw? |
Hmm, true if |
I had a look how Python is handling this. There exists a special flag:
They have two modes:
I do not like the first approach (and also JSON5), because it goes beyond RFC 7159. On the other hand, the serializer does not throw so far. |
- 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. |
in obverse to this, it would be really nice if get_arithmetic_value convert null to NaN or to some configurable value instead of raising an exception. |
Hi there,
Taking the example basic_json__CompatibleNumberFloatType.cpp from the documentation, if I add the following on L16:
Then I get a
std::domain_error
at the execution. I reckon anan
which is a double should be stored as is in thejson
. If I want to store anull
I can put anullptr
myself. Is there a particular reason this is not the case? I wouldn't mind having a method.set<T>(1.0/0.0)
which explicitly stores anan
without converting it to another type.The text was updated successfully, but these errors were encountered: