Commit 4e9b4f6d authored by abolz's avatar abolz

Return 0 if binary exponent is too small

parent f5e5d47f
......@@ -142,7 +142,10 @@ struct DiyFp {
uint64_t u64;
}u;
RAPIDJSON_ASSERT(f <= kDpHiddenBit + kDpSignificandMask);
RAPIDJSON_ASSERT(e >= kDpDenormalExponent);
if (e < kDpDenormalExponent) {
// Underflow.
return 0.0;
}
RAPIDJSON_ASSERT(e < kDpMaxExponent);
const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
static_cast<uint64_t>(e + kDpExponentBias);
......
......@@ -392,6 +392,15 @@ static void TestParseDouble() {
"83723677529752585477247372368372368547354737253685475529752",
6223372036854775808.0);
TEST_DOUBLE(fullPrecision, "1e-325", 0.0);
TEST_DOUBLE(fullPrecision, "1e-324", 0.0);
TEST_DOUBLE(fullPrecision, "2e-324", 0.0);
TEST_DOUBLE(fullPrecision, "2.4703282292062327e-324", 0.0);
TEST_DOUBLE(fullPrecision, "2.4703282292062328e-324", 2.4703282292062328e-324);
TEST_DOUBLE(fullPrecision, "2.48e-324", 2.48e-324);
TEST_DOUBLE(fullPrecision, "2.5e-324", 2.5e-324);
#undef TEST_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