From d621dc9e9c77f81e5c8a35b8dcc16dcd63351321 Mon Sep 17 00:00:00 2001 From: Mikhail Khachayants Date: Wed, 18 Dec 2024 00:01:27 +0200 Subject: [PATCH] Fix parsing 0.184467440737095516159 with kParseFullPrecisionFlag --- include/rapidjson/internal/strtod.h | 2 +- test/unittest/readertest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/internal/strtod.h b/include/rapidjson/internal/strtod.h index 55f0e38..57c8418 100644 --- a/include/rapidjson/internal/strtod.h +++ b/include/rapidjson/internal/strtod.h @@ -134,7 +134,7 @@ inline bool StrtodDiyFp(const Ch* decimals, int dLen, int dExp, double* result) int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 for (; i < dLen; i++) { if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || - (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > Ch('5'))) + (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] >= Ch('5'))) break; significand = significand * 10u + static_cast(decimals[i] - Ch('0')); } diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 06c7d75..8ff67d1 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -246,6 +246,7 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, "1.00000000001e-2147483638", 0.0); TEST_DOUBLE(fullPrecision, "0.017976931348623157e+310", 1.7976931348623157e+308); // Max double in another form TEST_DOUBLE(fullPrecision, "128.74836467836484838364836483643636483648e-336", 0.0); // Issue #1251 + TEST_DOUBLE(fullPrecision, "0.184467440737095516159", 0.184467440737095516159); // decimal part is 10 * (2^64 - 1) + 9 // Since // abs((2^-1022 - 2^-1074) - 2.2250738585072012e-308) = 3.109754131239141401123495768877590405345064751974375599... x 10^-324