mirror of
https://github.com/nlohmann/json.git
synced 2024-12-18 16:57:51 +08:00
Merge pull request #200 from twelsby/issue199
Fixed issue #199 - Small bugs in json.hpp (get_number) and unit.cpp (non-standard integer type test)
This commit is contained in:
commit
cd44e43457
1157
src/json.hpp
1157
src/json.hpp
File diff suppressed because it is too large
Load Diff
@ -7478,7 +7478,7 @@ class basic_json
|
|||||||
// Negative, parse with strtoll and attempt cast to
|
// Negative, parse with strtoll and attempt cast to
|
||||||
// number_integer_t
|
// number_integer_t
|
||||||
if (attempt_cast(std::strtoll(reinterpret_cast<typename string_t::const_pointer>(m_start), &endptr,
|
if (attempt_cast(std::strtoll(reinterpret_cast<typename string_t::const_pointer>(m_start), &endptr,
|
||||||
10), result.m_value.number_unsigned))
|
10), result.m_value.number_integer))
|
||||||
{
|
{
|
||||||
result.m_type = value_t::number_integer;
|
result.m_type = value_t::number_integer;
|
||||||
}
|
}
|
||||||
|
@ -12097,17 +12097,17 @@ TEST_CASE("regression tests")
|
|||||||
// unsigned integer parsing - expected to overflow and be stored as a float
|
// unsigned integer parsing - expected to overflow and be stored as a float
|
||||||
j = custom_json::parse("4294967296"); // 2^32
|
j = custom_json::parse("4294967296"); // 2^32
|
||||||
CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_float));
|
CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_float));
|
||||||
CHECK(j.get<float>() == 4294967296.0);
|
CHECK(j.get<float>() == 4294967296.0f);
|
||||||
|
|
||||||
// integer object creation - expected to wrap and still be stored as an integer
|
// integer object creation - expected to wrap and still be stored as an integer
|
||||||
j = -2147483649LL; // -2^31-1
|
j = -2147483649LL; // -2^31-1
|
||||||
CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_integer));
|
CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_integer));
|
||||||
CHECK(j.get<int32_t>() == 2147483647.0); // Wrap
|
CHECK(j.get<int32_t>() == 2147483647); // Wrap
|
||||||
|
|
||||||
// integer parsing - expected to overflow and be stored as a float
|
// integer parsing - expected to overflow and be stored as a float with rounding
|
||||||
j = custom_json::parse("-2147483648"); // -2^31
|
j = custom_json::parse("-2147483649"); // -2^31
|
||||||
CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_float));
|
CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_float));
|
||||||
CHECK(j.get<float>() == -2147483648.0);
|
CHECK(j.get<float>() == -2147483650.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("issue #93 reverse_iterator operator inheritance problem")
|
SECTION("issue #93 reverse_iterator operator inheritance problem")
|
||||||
|
Loading…
Reference in New Issue
Block a user