15 #ifndef RAPIDJSON_STRTOD_ 16 #define RAPIDJSON_STRTOD_ 28 inline double FastPath(
double significand,
int exp) {
60 const int hExp = bExp - 1;
62 int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0;
93 int common_Exp2 =
Min3(dS_Exp2, bS_Exp2, hS_Exp2);
94 dS_Exp2 -= common_Exp2;
95 bS_Exp2 -= common_Exp2;
96 hS_Exp2 -= common_Exp2;
99 dS.
MultiplyPow5(static_cast<unsigned>(dS_Exp5)) <<=
static_cast<unsigned>(dS_Exp2);
102 bS.
MultiplyPow5(static_cast<unsigned>(bS_Exp5)) <<=
static_cast<unsigned>(bS_Exp2);
105 hS.
MultiplyPow5(static_cast<unsigned>(hS_Exp5)) <<=
static_cast<unsigned>(hS_Exp2);
116 if (
p > 22 &&
p < 22 + 16) {
122 if (
p >= -22 &&
p <= 22 &&
d <= 9007199254740991.0) {
134 for (;
i < dLen;
i++) {
138 significand = significand * 10
u +
static_cast<unsigned>(decimals[
i] -
'0');
141 if (
i < dLen && decimals[
i] >=
'5')
144 int remaining = dLen -
i;
145 const int kUlpShift = 3;
146 const int kUlp = 1 << kUlpShift;
149 DiyFp v(significand, 0);
157 if (actualExp != dExp) {
158 static const DiyFp kPow10[] = {
167 int adjustment = dExp - actualExp;
169 v = v * kPow10[adjustment - 1];
170 if (dLen + adjustment > 19)
178 const int oldExp = v.
e;
183 int precisionSize = 64 - effectiveSignificandSize;
184 if (precisionSize + kUlpShift >= 64) {
185 int scaleExp = (precisionSize + kUlpShift) - 63;
189 precisionSize -= scaleExp;
192 DiyFp rounded(v.
f >> precisionSize, v.
e + precisionSize);
193 const uint64_t precisionBits = (v.
f & ((
uint64_t(1) << precisionSize) - 1)) * kUlp;
195 if (precisionBits >= halfWay + static_cast<unsigned>(
error)) {
205 return halfWay -
static_cast<unsigned>(
error) >= precisionBits || precisionBits >= halfWay + static_cast<unsigned>(
error);
210 const BigInteger dInt(decimals, static_cast<unsigned>(dLen));
217 if (
a.Significand() & 1)
218 return a.NextPositiveDouble();
223 return a.NextPositiveDouble();
226 inline double StrtodFullPrecision(
double d,
int p,
const char* decimals,
size_t length,
size_t decimalPosition,
int exp) {
235 int dLen =
static_cast<int>(length);
239 int dExpAdjust =
static_cast<int>(length - decimalPosition);
242 int dExp = exp - dExpAdjust;
248 while (dLen > 0 && *decimals ==
'0') {
254 while (dLen > 0 && decimals[dLen - 1] ==
'0') {
264 const int kMaxDecimalDigit = 767 + 1;
265 if (dLen > kMaxDecimalDigit) {
266 dExp += dLen - kMaxDecimalDigit;
267 dLen = kMaxDecimalDigit;
272 if (dLen + dExp <= -324)
277 if (dLen + dExp > 309)
278 return std::numeric_limits<double>::infinity();
290 #endif // RAPIDJSON_STRTOD_ int Compare(const BigInteger &rhs) const
Definition: biginteger.h:208
const uint32_t T[512]
Definition: groestl_tables.h:36
double StrtodFullPrecision(double d, int p, const char *decimals, size_t length, size_t decimalPosition, int exp)
Definition: strtod.h:226
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:294
int i
Definition: pymoduletest.py:23
u
Definition: pymoduletest.py:20
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
DiyFp GetCachedPower10(int exp, int *outExp)
Definition: diyfp.h:252
tools::wallet2::message_signature_result_t result
Definition: signature.cpp:62
static int EffectiveSignificandSize(int order)
Definition: ieee754.h:51
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
bool StrtodFast(double d, int p, double *result)
Definition: strtod.h:113
double ToDouble() const
Definition: diyfp.h:141
double StrtodNormalPrecision(double d, int p)
Definition: strtod.h:37
int CheckWithinHalfULP(double b, const BigInteger &d, int dExp)
Definition: strtod.h:56
bool StrtodDiyFp(const char *decimals, int dLen, int dExp, double *result)
Definition: strtod.h:131
unsigned __int64 uint64_t
Definition: stdint.h:136
uint64_t f
Definition: diyfp.h:171
int IntegerExponent() const
Definition: ieee754.h:48
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
uint64_t IntegerSignificand() const
Definition: ieee754.h:47
Definition: document.h:406
double Pow10(int n)
Computes integer powers of 10 in double (10.0^n).
Definition: pow10.h:28
signed __int64 int64_t
Definition: stdint.h:135
double StrtodBigInteger(double approx, const char *decimals, int dLen, int dExp)
Definition: strtod.h:208
d
Definition: pymoduletest.py:79
p
Definition: pymoduletest.py:75
T Min3(T a, T b, T c)
Definition: strtod.h:49
DiyFp Normalize() const
Definition: diyfp.h:102
int e
Definition: diyfp.h:172
bool Difference(const BigInteger &rhs, BigInteger *out) const
Definition: biginteger.h:186
Definition: biginteger.h:28
error
Tracks LMDB error codes.
Definition: error.h:44
BigInteger & MultiplyPow5(unsigned exp)
Definition: biginteger.h:162
static const uint64_t kDpHiddenBit
Definition: diyfp.h:169
double FastPath(double significand, int exp)
Definition: strtod.h:28
c
Definition: pymoduletest.py:79
cryptonote::block b
Definition: block.cpp:40