mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-08-04 10:36:23 -04:00
Run clang tidy
This commit is contained in:
parent
bea8350346
commit
298ca1eab4
@ -88,7 +88,7 @@ static inline bool InRange(double d, T min, U max) {
|
||||
// The casts can lose precision, but we are looking only for
|
||||
// an approximate range. Might fail on edge cases though. ~cdunn
|
||||
return d >= static_cast<double>(min) && d <= static_cast<double>(max) &&
|
||||
!(static_cast<U>(d) == min && d != static_cast<double>(min));
|
||||
!(static_cast<U>(d) == min && d != static_cast<double>(min));
|
||||
}
|
||||
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
||||
static inline double integerToDouble(Json::UInt64 value) {
|
||||
@ -707,10 +707,11 @@ Value::Int64 Value::asInt64() const {
|
||||
JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range");
|
||||
return Int64(value_.uint_);
|
||||
case realValue:
|
||||
// If the double value is in proximity to minInt64, it will be rounded to minInt64.
|
||||
// The correct value in this scenario is indeterminable
|
||||
JSON_ASSERT_MESSAGE(value_.real_ != minInt64,
|
||||
"Double value is minInt64, precise value cannot be determined");
|
||||
// If the double value is in proximity to minInt64, it will be rounded to
|
||||
// minInt64. The correct value in this scenario is indeterminable
|
||||
JSON_ASSERT_MESSAGE(
|
||||
value_.real_ != minInt64,
|
||||
"Double value is minInt64, precise value cannot be determined");
|
||||
JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64),
|
||||
"double out of Int64 range");
|
||||
return Int64(value_.real_);
|
||||
@ -1317,11 +1318,12 @@ bool Value::isInt64() const {
|
||||
// Note that maxInt64 (= 2^63 - 1) is not exactly representable as a
|
||||
// double, so double(maxInt64) will be rounded up to 2^63. Therefore we
|
||||
// require the value to be strictly less than the limit.
|
||||
// minInt64 is -2^63 which can be represented as a double, but since double values in its proximity are also
|
||||
// rounded to -2^63, we require the value to be strictly greater than the limit to avoid returning
|
||||
// 'true' for values that are not in the range
|
||||
return value_.real_ > double(minInt64) &&
|
||||
value_.real_ < double(maxInt64) && IsIntegral(value_.real_);
|
||||
// minInt64 is -2^63 which can be represented as a double, but since double
|
||||
// values in its proximity are also rounded to -2^63, we require the value
|
||||
// to be strictly greater than the limit to avoid returning 'true' for
|
||||
// values that are not in the range
|
||||
return value_.real_ > double(minInt64) && value_.real_ < double(maxInt64) &&
|
||||
IsIntegral(value_.real_);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1359,9 +1361,10 @@ bool Value::isIntegral() const {
|
||||
// Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
|
||||
// double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
|
||||
// require the value to be strictly less than the limit.
|
||||
// minInt64 is -2^63 which can be represented as a double, but since double values in its proximity are also
|
||||
// rounded to -2^63, we require the value to be strictly greater than the limit to avoid returning
|
||||
// 'true' for values that are not in the range
|
||||
// minInt64 is -2^63 which can be represented as a double, but since double
|
||||
// values in its proximity are also rounded to -2^63, we require the value
|
||||
// to be strictly greater than the limit to avoid returning 'true' for
|
||||
// values that are not in the range
|
||||
return value_.real_ > double(minInt64) &&
|
||||
value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
|
||||
#else
|
||||
|
@ -1191,8 +1191,8 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, integers) {
|
||||
JSONTEST_ASSERT_EQUAL(true, val.asBool());
|
||||
JSONTEST_ASSERT_STRING_EQUAL("-9223372036854775808", val.asString());
|
||||
|
||||
// int64 min (floating point constructor). Since double values in proximity of kint64min
|
||||
// are rounded to kint64min, we don't check for conversion to int64.
|
||||
// int64 min (floating point constructor). Since double values in proximity of
|
||||
// kint64min are rounded to kint64min, we don't check for conversion to int64.
|
||||
val = Json::Value(double(kint64min));
|
||||
|
||||
JSONTEST_ASSERT_EQUAL(Json::realValue, val.type());
|
||||
|
Loading…
x
Reference in New Issue
Block a user