Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiloyip <miloyip@gmail.com>2014-09-03 10:45:37 +0400
committermiloyip <miloyip@gmail.com>2014-09-03 10:45:37 +0400
commitb0436911a8ce2b7e2aa73972d5275702a60cc3ae (patch)
tree6318e6f1375f865f3cbe85bcecbc6d4f8be839ff
parent818f6f1f2e7158369a2d2029b6962764ab70c22a (diff)
Check "fast path cases in disguise" in strtod
-rw-r--r--include/rapidjson/reader.h14
-rw-r--r--test/unittest/readertest.cpp1
2 files changed, 13 insertions, 2 deletions
diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h
index 0615ce2d..92deeab7 100644
--- a/include/rapidjson/reader.h
+++ b/include/rapidjson/reader.h
@@ -877,11 +877,21 @@ private:
if (useDouble) {
int p = exp + expFrac;
double d;
- uint64_t significand = use64bit ? i64 : i;
+ double significand = use64bit ? i64 : i;
// Use fast path for string-to-double conversion if possible
// see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/
- if (!useStrtod && p >= -22 && p <= 22 && significand <= RAPIDJSON_UINT64_C2(0x001FFFFF, 0xFFFFFFFF)) {
+ if (!useStrtod && p > 22) {
+ if (p < 22 + 16) {
+ // Fast Path Cases In Disguise
+ significand *= internal::Pow10(p - 22);
+ p = 22;
+ }
+ else
+ useStrtod = true;
+ }
+
+ if (!useStrtod && p >= -22 && significand <= 9007199254740991.0) { // 2^53 - 1
if (p >= 0)
d = significand * internal::Pow10(p);
else
diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp
index 104bcd23..bbfbae5b 100644
--- a/test/unittest/readertest.cpp
+++ b/test/unittest/readertest.cpp
@@ -165,6 +165,7 @@ TEST(Reader, ParseNumberHandler) {
TEST_DOUBLE("18446744073709551616", 18446744073709551616.0); // 2^64 (max of uint64_t + 1, force to use double)
TEST_DOUBLE("-9223372036854775809", -9223372036854775809.0); // -2^63 - 1(min of int64_t + 1, force to use double)
TEST_DOUBLE("0.9868011474609375", 0.9868011474609375); // https://github.com/miloyip/rapidjson/issues/120
+ TEST_DOUBLE("123e34", 123e34); // Fast Path Cases In Disguise
{
char n1e308[310]; // '1' followed by 308 '0'