19 #ifndef RAPIDJSON_DTOA_
20 #define RAPIDJSON_DTOA_
31 RAPIDJSON_DIAG_OFF(effc++)
32 RAPIDJSON_DIAG_OFF(array - bounds)
39 while(rest < wp_w && delta - rest >= ten_kappa &&
40 (rest + ten_kappa < wp_w ||
41 wp_w - rest > rest + ten_kappa - wp_w))
76 static const uint64_t kPow10[] = {1ULL,
93 100000000000000000ULL,
94 1000000000000000000ULL,
95 10000000000000000000ULL};
97 const DiyFp wp_w = Mp - W;
147 buffer[(*len)++] =
static_cast<char>(
'0' +
static_cast<char>(d));
153 GrisuRound(buffer, *len, delta, tmp, kPow10[kappa] << -one.
e, wp_w.
f);
163 char d =
static_cast<char>(p2 >> -one.
e);
165 buffer[(*len)++] =
static_cast<char>(
'0' + d);
172 GrisuRound(buffer, *len, delta, p2, one.
f, wp_w.
f * (index < 20 ? kPow10[index] : 0));
178 inline void Grisu2(
double value,
char* buffer,
int* length,
int* K)
186 DiyFp Wp = w_p * c_mk;
187 DiyFp Wm = w_m * c_mk;
190 DigitGen(W, Wp, Wp.
f - Wm.
f, buffer, length, K);
203 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K / 100));
216 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K));
221 inline char*
Prettify(
char* buffer,
int length,
int k,
int maxDecimalPlaces)
223 const int kk = length + k;
225 if(0 <= k && kk <= 21)
228 for(
int i = length; i < kk; i++)
231 buffer[kk + 1] =
'0';
232 return &buffer[kk + 2];
234 else if(0 < kk && kk <= 21)
237 std::memmove(&buffer[kk + 1], &buffer[kk],
static_cast<size_t>(length - kk));
239 if(0 > k + maxDecimalPlaces)
243 for(
int i = kk + maxDecimalPlaces; i > kk + 1; i--)
245 return &buffer[i + 1];
246 return &buffer[kk + 2];
249 return &buffer[length + 1];
251 else if(-6 < kk && kk <= 0)
254 const int offset = 2 - kk;
255 std::memmove(&buffer[offset], &buffer[0],
static_cast<size_t>(length));
258 for(
int i = 2; i < offset; i++)
260 if(length - kk > maxDecimalPlaces)
264 for(
int i = maxDecimalPlaces + 1; i > 2; i--)
266 return &buffer[i + 1];
270 return &buffer[length + offset];
272 else if(kk < -maxDecimalPlaces)
289 std::memmove(&buffer[2], &buffer[1],
static_cast<size_t>(length - 1));
291 buffer[length + 1] =
'e';
296 inline char*
dtoa(
double value,
char* buffer,
int maxDecimalPlaces = 324)
318 return Prettify(buffer, length, K, maxDecimalPlaces);
bool IsZero() const
Definition: ieee754.h:50
bool Sign() const
Definition: ieee754.h:39
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:451
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
Definition: allocators.h:459
char * Prettify(char *buffer, int length, int k, int maxDecimalPlaces)
Definition: dtoa.h:221
void GrisuRound(char *buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w)
Definition: dtoa.h:37
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition: dtoa.h:296
void DigitGen(const DiyFp &W, const DiyFp &Mp, uint64_t delta, char *buffer, int *len, int *K)
Definition: dtoa.h:74
int CountDecimalDigit32(uint32_t n)
Definition: dtoa.h:48
const char * GetDigitsLut()
Definition: itoa.h:23
DiyFp GetCachedPower(int e, int *K)
Definition: diyfp.h:239
char * WriteExponent(int K, char *buffer)
Definition: dtoa.h:193
void Grisu2(double value, char *buffer, int *length, int *K)
Definition: dtoa.h:178
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1697
unsigned int uint32_t
Definition: stdint.h:126
unsigned __int64 uint64_t
Definition: stdint.h:136
uint64_t f
Definition: diyfp.h:175
DiyFp Normalize() const
Definition: diyfp.h:111
void NormalizedBoundaries(DiyFp *minus, DiyFp *plus) const
Definition: diyfp.h:130
int e
Definition: diyfp.h:176