15 #ifndef RAPIDJSON_STRTOD_ 16 #define RAPIDJSON_STRTOD_ 18 #include "../rapidjson.h" 27 inline double FastPath(
double significand,
int exp) {
59 const int hExp = bExp - 1;
61 int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0;
92 int common_Exp2 =
Min3(dS_Exp2, bS_Exp2, hS_Exp2);
93 dS_Exp2 -= common_Exp2;
94 bS_Exp2 -= common_Exp2;
95 hS_Exp2 -= common_Exp2;
98 dS.
MultiplyPow5(static_cast<unsigned>(dS_Exp5)) <<=
static_cast<unsigned>(dS_Exp2);
101 bS.
MultiplyPow5(static_cast<unsigned>(bS_Exp5)) <<=
static_cast<unsigned>(bS_Exp2);
104 hS.
MultiplyPow5(static_cast<unsigned>(hS_Exp5)) <<=
static_cast<unsigned>(hS_Exp2);
115 if (p > 22 && p < 22 + 16) {
121 if (p >= -22 && p <= 22 && d <= 9007199254740991.0) {
137 significand = significand * 10u +
static_cast<unsigned>(decimals[i] -
'0');
140 if (i < length && decimals[i] >=
'5')
143 size_t remaining = length - i;
144 const unsigned kUlpShift = 3;
145 const unsigned kUlp = 1 << kUlpShift;
146 int error = (remaining == 0) ? 0 : kUlp / 2;
152 const int dExp = (
int)decimalPosition - (
int)i + exp;
156 if (actualExp != dExp) {
157 static const DiyFp kPow10[] = {
166 int adjustment = dExp - actualExp - 1;
168 v = v * kPow10[adjustment];
169 if (length + static_cast<unsigned>(adjustment)> 19u)
175 error += kUlp + (error == 0 ? 0 : 1);
177 const int oldExp = v.
e;
179 error <<= oldExp - v.
e;
182 unsigned precisionSize = 64 - effectiveSignificandSize;
183 if (precisionSize + kUlpShift >= 64) {
184 unsigned scaleExp = (precisionSize + kUlpShift) - 63;
187 error = (error >> scaleExp) + 1 + static_cast<int>(kUlp);
188 precisionSize -= scaleExp;
191 DiyFp rounded(v.
f >> precisionSize, v.
e + static_cast<int>(precisionSize));
192 const uint64_t precisionBits = (v.
f & ((
uint64_t(1) << precisionSize) - 1)) * kUlp;
194 if (precisionBits >= halfWay + static_cast<unsigned>(error)) {
204 return halfWay -
static_cast<unsigned>(error) >= precisionBits || precisionBits >= halfWay + static_cast<unsigned>(error);
209 const int dExp = (
int)decimalPosition - (
int)length + exp;
234 while (*decimals ==
'0' && length > 1) {
241 while (decimals[length - 1] ==
'0' && length > 1) {
248 const int kMaxDecimalDigit = 780;
249 if ((
int)length > kMaxDecimalDigit) {
250 int delta = (
int(length) - kMaxDecimalDigit);
252 decimalPosition -=
static_cast<unsigned>(delta);
253 length = kMaxDecimalDigit;
257 if (
int(length) + exp < -324)
260 if (
StrtodDiyFp(decimals, length, decimalPosition, exp, &result))
270 #endif // RAPIDJSON_STRTOD_
double StrtodFullPrecision(double d, int p, const char *decimals, size_t length, size_t decimalPosition, int exp)
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
uint64_t IntegerSignificand() const
DiyFp GetCachedPower10(int exp, int *outExp)
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
uint64_t Significand() const
GLuint GLsizei GLsizei * length
int Compare(const BigInteger &rhs) const
GLdouble GLdouble GLdouble b
BigInteger & MultiplyPow5(unsigned exp)
bool StrtodFast(double d, int p, double *result)
double StrtodNormalPrecision(double d, int p)
int CheckWithinHalfULP(double b, const BigInteger &d, int dExp)
bool Difference(const BigInteger &rhs, BigInteger *out) const
double StrtodBigInteger(double approx, const char *decimals, size_t length, size_t decimalPosition, int exp)
unsigned __int64 uint64_t
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
double Pow10(int n)
Computes integer powers of 10 in double (10.0^n).
double NextPositiveDouble() const
bool StrtodDiyFp(const char *decimals, size_t length, size_t decimalPosition, int exp, double *result)
static unsigned EffectiveSignificandSize(int order)
GLboolean GLboolean GLboolean GLboolean a
#define RAPIDJSON_ASSERT(x)
Assertion.
double FastPath(double significand, int exp)
static const uint64_t kDpHiddenBit
int IntegerExponent() const