You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I read the article about Number Handling (nan-handling)
In it there is an example of a double variable being converted to json and back.
I have extended this example somewhat (see below) by parsing the dumped json object and attempt to convert/assign it to another double variable.
This fails with an exception:
terminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.302] type must be number, but is null
Instead, of generating an exception, I would expect that (for results of float, double, and long double type) the conversion would result in a nan value as it did with the original example...
And what is the actual behavior instead?
The conversion to a double variable fails with an exception:
terminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.302] type must be number, but is null
Which compiler and operating system are you using?
I don't believe that this is dependent of either OS or compiler, but at 'godbolt' I see the following:
Compiler: gcc 11.2
Operating system: Not sure what godbolt is using. I assume that it is Linux...
Which version of the library did you use?
other release - 3.6.0
other release - 'Whatever godbolt refers to as 'trunk'.
OK, now I get it.
I was thrown off by that example. I thought that while indeed NaN was not part of JSON, the null representation as printed by the example was nlohmann::json's way of coping with it.
Thank you both for your explanation and your time.
What is the issue you have?
I read the article about Number Handling (nan-handling)
In it there is an example of a
double
variable being converted to json and back.I have extended this example somewhat (see below) by parsing the dumped json object and attempt to convert/assign it to another
double
variable.This fails with an exception:
Please describe the steps to reproduce the issue.
See the code at: godbolt.org
In case that that doesn't work, here is the code:
The generated output is:
Followed by the error message shown above.
Can you provide a small but working code example?
What is the expected behavior?
Instead, of generating an exception, I would expect that (for results of
float
,double
, andlong double
type) the conversion would result in a nan value as it did with the original example...And what is the actual behavior instead?
The conversion to a
double
variable fails with an exception:Which compiler and operating system are you using?
I don't believe that this is dependent of either OS or compiler, but at 'godbolt' I see the following:
Which version of the library did you use?
If you experience a compilation error: can you compile and run the unit tests?
The text was updated successfully, but these errors were encountered: