Commit 1acfc216 authored by Milo Yip's avatar Milo Yip

Merge pull request #34 from miloyip/SmallFloatingPoint

Fixes parsing small floating point values underflow
parents 2e156cca 4843b790
......@@ -664,7 +664,15 @@ private:
// Finish parsing, call event according to the type of number.
if (useDouble) {
d *= internal::Pow10(exp + expFrac);
int expSum = exp + expFrac;
if (expSum < -308) {
// Prevent expSum < -308, making Pow10(expSum) = 0
d *= internal::Pow10(exp);
d *= internal::Pow10(expFrac);
}
else
d *= internal::Pow10(expSum);
handler.Double(minus ? -d : d);
}
else {
......
......@@ -129,9 +129,9 @@ TEST(Reader, ParseNumberHandler) {
TEST_DOUBLE("1.234E+10", 1.234E+10);
TEST_DOUBLE("1.234E-10", 1.234E-10);
TEST_DOUBLE("1.79769e+308", 1.79769e+308);
//TEST_DOUBLE("2.22507e-308", 2.22507e-308); // TODO: underflow
TEST_DOUBLE("2.22507e-308", 2.22507e-308);
TEST_DOUBLE("-1.79769e+308", -1.79769e+308);
//TEST_DOUBLE("-2.22507e-308", -2.22507e-308); // TODO: underflow
TEST_DOUBLE("-2.22507e-308", -2.22507e-308);
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)
......
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