From 2689cc4974f314b99716b6fbad137e7e1bcecfdb Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 11:52:24 +0800 Subject: [PATCH] Remove more unused code paths in double conversions --- include/rapidjson/internal/biginteger.h | 7 ++----- include/rapidjson/internal/strtod.h | 14 ++------------ 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/include/rapidjson/internal/biginteger.h b/include/rapidjson/internal/biginteger.h index b088204..5baba9b 100755 --- a/include/rapidjson/internal/biginteger.h +++ b/include/rapidjson/internal/biginteger.h @@ -172,13 +172,10 @@ public: } // Compute absolute difference of this and rhs. - // Return false if this < rhs + // Assume this != rhs bool Difference(const BigInteger& rhs, BigInteger* out) const { int cmp = Compare(rhs); - if (cmp == 0) { - *out = BigInteger(0); - return false; - } + RAPIDJSON_ASSERT(cmp != 0); const BigInteger *a, *b; // Makes a > b bool ret; if (cmp < 0) { a = &rhs; b = this; ret = true; } diff --git a/include/rapidjson/internal/strtod.h b/include/rapidjson/internal/strtod.h index 6644f37..fa85286 100644 --- a/include/rapidjson/internal/strtod.h +++ b/include/rapidjson/internal/strtod.h @@ -104,19 +104,9 @@ inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { hS.MultiplyPow5(hS_Exp5) <<= hS_Exp2; BigInteger delta(0); - bool adjustToNegative = dS.Difference(bS, &delta); + dS.Difference(bS, &delta); - int cmp = delta.Compare(hS); - // If delta is within 1/2 ULP, check for special case when significand is power of two. - // In this case, need to compare with 1/2h in the lower bound. - if (cmp < 0 && adjustToNegative && // within and dS < bS - db.IsNormal() && (bInt & (bInt - 1)) == 0 && // Power of 2 - db.Uint64Value() != RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)) // minimum normal number must not do this - { - delta <<= 1; - return delta.Compare(hS); - } - return cmp; + return delta.Compare(hS); } inline bool StrtodFast(double d, int p, double* result) {