From 55f8339a0a567e07dabbd3bd16198c138b0430c3 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 11 Apr 2015 11:26:47 +0800 Subject: [PATCH 1/2] Compare exact binary representation for full precision test Conflicts: doc/diagram/simpledom.png --- test/unittest/readertest.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index d41eed6..8c8c63c 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -189,14 +189,15 @@ static void TestParseDouble() { ASSERT_EQ(kParseErrorNone, reader.Parse(s, h).Code()); \ EXPECT_EQ(1u, h.step_); \ internal::Double e(x), a(h.actual_); \ - EXPECT_EQ(e.Sign(), a.Sign()); \ if (fullPrecision) { \ - EXPECT_NEAR(x, h.actual_, 0.0); \ - if (x != h.actual_) \ - printf(" String: %s\n Actual: %.17g\nExpected: %.17g\n", str, h.actual_, x); \ + EXPECT_EQ(e.Uint64Value(), a.Uint64Value()); \ + if (e.Uint64Value() != a.Uint64Value()) \ + 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_); \ + } \ } TEST_DOUBLE(fullPrecision, "0.0", 0.0); From cb59a5a9a2c7a0e93a6f23278a0ca3dead195f11 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 11 Apr 2015 11:34:44 +0800 Subject: [PATCH 2/2] Correct the Value::operator==() for double. --- include/rapidjson/document.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 82a86ed..8cc968a 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -701,8 +701,9 @@ public: case kNumberType: if (IsDouble() || rhs.IsDouble()) { - float delta = GetDouble() - rhs.GetDouble(); // May convert one operand from integer to double. - return delta >= 0.0 && delta <= 0.0; // Prevent -Wfloat-equal + double a = GetDouble(); // May convert from integer to double. + double b = rhs.GetDouble(); // Ditto + return a >= b && a <= b; // Prevent -Wfloat-equal } else return data_.n.u64 == rhs.data_.n.u64;