Commit a2813b67 authored by abolz's avatar abolz

Limit exponents

parent 6cd5cd7b
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "diyfp.h" #include "diyfp.h"
#include "pow10.h" #include "pow10.h"
#include <climits> #include <climits>
#include <limits>
RAPIDJSON_NAMESPACE_BEGIN RAPIDJSON_NAMESPACE_BEGIN
namespace internal { namespace internal {
...@@ -260,16 +261,22 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t ...@@ -260,16 +261,22 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
} }
// Trim right-most digits // Trim right-most digits
const int kMaxDecimalDigit = 780; const int kMaxDecimalDigit = 767 + 1;
if (dLen > kMaxDecimalDigit) { if (dLen > kMaxDecimalDigit) {
dExp += dLen - kMaxDecimalDigit; dExp += dLen - kMaxDecimalDigit;
dLen = kMaxDecimalDigit; dLen = kMaxDecimalDigit;
} }
// If too small, underflow to zero // If too small, underflow to zero.
if (dLen + dExp < -324) // Any x <= 10^-324 is interpreted as zero.
if (dLen + dExp <= -324)
return 0.0; return 0.0;
// If too large, overflow to infinity.
// Any x >= 10^309 is interpreted as +infinity.
if (dLen + dExp > 309)
return std::numeric_limits<double>::infinity();
if (StrtodDiyFp(decimals, dLen, dExp, &result)) if (StrtodDiyFp(decimals, dLen, dExp, &result))
return result; return result;
......
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