Merge pull request #295 from miloyip/issue287_WarningFloatEqual
Fix several -Wfloat-equal related comments in #293
This commit is contained in:
commit
6f4337c555
@ -701,8 +701,9 @@ public:
|
|||||||
|
|
||||||
case kNumberType:
|
case kNumberType:
|
||||||
if (IsDouble() || rhs.IsDouble()) {
|
if (IsDouble() || rhs.IsDouble()) {
|
||||||
float delta = GetDouble() - rhs.GetDouble(); // May convert one operand from integer to double.
|
double a = GetDouble(); // May convert from integer to double.
|
||||||
return delta >= 0.0 && delta <= 0.0; // Prevent -Wfloat-equal
|
double b = rhs.GetDouble(); // Ditto
|
||||||
|
return a >= b && a <= b; // Prevent -Wfloat-equal
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return data_.n.u64 == rhs.data_.n.u64;
|
return data_.n.u64 == rhs.data_.n.u64;
|
||||||
|
@ -189,14 +189,15 @@ static void TestParseDouble() {
|
|||||||
ASSERT_EQ(kParseErrorNone, reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h).Code()); \
|
ASSERT_EQ(kParseErrorNone, reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h).Code()); \
|
||||||
EXPECT_EQ(1u, h.step_); \
|
EXPECT_EQ(1u, h.step_); \
|
||||||
internal::Double e(x), a(h.actual_); \
|
internal::Double e(x), a(h.actual_); \
|
||||||
EXPECT_EQ(e.Sign(), a.Sign()); \
|
|
||||||
if (fullPrecision) { \
|
if (fullPrecision) { \
|
||||||
EXPECT_NEAR(x, h.actual_, 0.0); \
|
EXPECT_EQ(e.Uint64Value(), a.Uint64Value()); \
|
||||||
if (x != h.actual_) \
|
if (e.Uint64Value() != a.Uint64Value()) \
|
||||||
printf(" String: %s\n Actual: %.17g\nExpected: %.17g\n", str, h.actual_, x); \
|
printf(" String: %s\n Actual: %.17g\nExpected: %.17g\n", str, h.actual_, x); \
|
||||||
} \
|
} \
|
||||||
else \
|
else { \
|
||||||
|
EXPECT_EQ(e.Sign(), a.Sign()); /* for 0.0 != -0.0 */ \
|
||||||
EXPECT_DOUBLE_EQ(x, h.actual_); \
|
EXPECT_DOUBLE_EQ(x, h.actual_); \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_DOUBLE(fullPrecision, "0.0", 0.0);
|
TEST_DOUBLE(fullPrecision, "0.0", 0.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user