Commit 2452afbf authored by Milo Yip's avatar Milo Yip

Fix -Wfloat-equal warnings in Value::operator== and valuetest

parent e04d66bd
...@@ -700,8 +700,10 @@ public: ...@@ -700,8 +700,10 @@ public:
return StringEqual(rhs); return StringEqual(rhs);
case kNumberType: case kNumberType:
if (IsDouble() || rhs.IsDouble()) if (IsDouble() || rhs.IsDouble()) {
return GetDouble() == rhs.GetDouble(); // May convert one operand from integer to double. float delta = GetDouble() - rhs.GetDouble(); // May convert one operand from integer to double.
return delta >= 0.0 && delta <= 0.0; // Prevent -Wfloat-equal
}
else else
return data_.n.u64 == rhs.data_.n.u64; return data_.n.u64 == rhs.data_.n.u64;
......
...@@ -339,7 +339,7 @@ TEST(Value, Int) { ...@@ -339,7 +339,7 @@ TEST(Value, Int) {
EXPECT_EQ(1234u, x.GetUint()); EXPECT_EQ(1234u, x.GetUint());
EXPECT_EQ(1234, x.GetInt64()); EXPECT_EQ(1234, x.GetInt64());
EXPECT_EQ(1234u, x.GetUint64()); EXPECT_EQ(1234u, x.GetUint64());
EXPECT_EQ(1234, x.GetDouble()); EXPECT_NEAR(1234.0, x.GetDouble(), 0.0);
//EXPECT_EQ(1234, (int)x); //EXPECT_EQ(1234, (int)x);
//EXPECT_EQ(1234, (unsigned)x); //EXPECT_EQ(1234, (unsigned)x);
//EXPECT_EQ(1234, (int64_t)x); //EXPECT_EQ(1234, (int64_t)x);
...@@ -397,7 +397,7 @@ TEST(Value, Uint) { ...@@ -397,7 +397,7 @@ TEST(Value, Uint) {
EXPECT_TRUE(x.IsUint()); EXPECT_TRUE(x.IsUint());
EXPECT_TRUE(x.IsInt64()); EXPECT_TRUE(x.IsInt64());
EXPECT_TRUE(x.IsUint64()); EXPECT_TRUE(x.IsUint64());
EXPECT_EQ(1234.0, x.GetDouble()); // Number can always be cast as double but !IsDouble(). EXPECT_NEAR(1234.0, x.GetDouble(), 0.0); // Number can always be cast as double but !IsDouble().
EXPECT_FALSE(x.IsDouble()); EXPECT_FALSE(x.IsDouble());
EXPECT_FALSE(x.IsNull()); EXPECT_FALSE(x.IsNull());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment