Skip to content

Commit cb009f3

Browse files
committed
Return infinity if binary exponent is too large
1 parent 7acbb87 commit cb009f3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/rapidjson/internal/diyfp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define RAPIDJSON_DIYFP_H_
2121

2222
#include "../rapidjson.h"
23+
#include <limits>
2324

2425
#if defined(_MSC_VER) && defined(_M_AMD64) && !defined(__INTEL_COMPILER)
2526
#include <intrin.h>
@@ -146,7 +147,10 @@ struct DiyFp {
146147
// Underflow.
147148
return 0.0;
148149
}
149-
RAPIDJSON_ASSERT(e < kDpMaxExponent);
150+
if (e >= kDpMaxExponent) {
151+
// Overflow.
152+
return std::numeric_limits<double>::infinity();
153+
}
150154
const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
151155
static_cast<uint64_t>(e + kDpExponentBias);
152156
u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);

0 commit comments

Comments
 (0)