💥 implemented new handling of NaN and INF #70 #329 #388

- 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 commit is contained in:
Niels Lohmann 2017-03-12 18:38:05 +01:00
parent 9355f05888
commit 8feaf8dc94
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
8 changed files with 100 additions and 46 deletions

View file

@ -702,11 +702,17 @@ TEST_CASE("constructors")
SECTION("infinity")
{
// infinity is stored as null
// should change in the future: https://github.com/nlohmann/json/issues/388
// infinity is stored properly, but serialized to null
json::number_float_t n(std::numeric_limits<json::number_float_t>::infinity());
json j(n);
CHECK(j.type() == json::value_t::null);
CHECK(j.type() == json::value_t::number_float);
// check round trip of infinity
json::number_float_t d = j;
CHECK(d == n);
// check that inf is serialized to null
CHECK(j.dump() == "null");
}
}