19 #ifndef RAPIDJSON_DTOA_ 20 #define RAPIDJSON_DTOA_ 31 RAPIDJSON_DIAG_OFF(effc++)
32 RAPIDJSON_DIAG_OFF(array-bounds)
38 while (rest < wp_w && delta - rest >= ten_kappa && (rest + ten_kappa < wp_w ||
39 wp_w - rest > rest + ten_kappa - wp_w))
73 static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
75 const DiyFp wp_w = Mp - W;
125 buffer[(*len)++] =
static_cast<char>(
'0' +
static_cast<char>(d));
131 GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.
e, wp_w.
f);
141 char d =
static_cast<char>(p2 >> -one.
e);
143 buffer[(*len)++] =
static_cast<char>(
'0' + d);
150 GrisuRound(buffer, *len, delta, p2, one.
f, wp_w.
f * (index < 9 ? kPow10[index] : 0));
156 inline void Grisu2(
double value,
char* buffer,
int* length,
int* K)
158 const DiyFp v(value);
164 DiyFp Wp = w_p * c_mk;
165 DiyFp Wm = w_m * c_mk;
168 DigitGen(W, Wp, Wp.
f - Wm.
f, buffer, length, K);
181 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K / 100));
194 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K));
199 inline char*
Prettify(
char* buffer,
int length,
int k,
int maxDecimalPlaces)
201 const int kk = length + k;
203 if (0 <= k && kk <= 21)
206 for (
int i = length; i < kk; i++)
209 buffer[kk + 1] =
'0';
210 return &buffer[kk + 2];
212 else if (0 < kk && kk <= 21)
215 std::memmove(&buffer[kk + 1], &buffer[kk], static_cast<size_t>(length - kk));
217 if (0 > k + maxDecimalPlaces)
221 for (
int i = kk + maxDecimalPlaces; i > kk + 1; i--)
222 if (buffer[i] !=
'0')
223 return &buffer[i + 1];
224 return &buffer[kk + 2];
227 return &buffer[length + 1];
229 else if (-6 < kk && kk <= 0)
232 const int offset = 2 - kk;
233 std::memmove(&buffer[offset], &buffer[0], static_cast<size_t>(length));
236 for (
int i = 2; i < offset; i++)
238 if (length - kk > maxDecimalPlaces)
242 for (
int i = maxDecimalPlaces + 1; i > 2; i--)
243 if (buffer[i] !=
'0')
244 return &buffer[i + 1];
248 return &buffer[length + offset];
250 else if (kk < -maxDecimalPlaces)
258 else if (length == 1)
267 std::memmove(&buffer[2], &buffer[1], static_cast<size_t>(length - 1));
269 buffer[length + 1] =
'e';
274 inline char*
dtoa(
double value,
char* buffer,
int maxDecimalPlaces = 324)
295 Grisu2(value, buffer, &length, &K);
296 return Prettify(buffer, length, K, maxDecimalPlaces);
307 #endif // RAPIDJSON_DTOA_
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
char * Prettify(char *buffer, int length, int k, int maxDecimalPlaces)
const char * GetDigitsLut()
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
void Grisu2(double value, char *buffer, int *length, int *K)
void GrisuRound(char *buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w)
unsigned __int64 uint64_t
void DigitGen(const DiyFp &W, const DiyFp &Mp, uint64_t delta, char *buffer, int *len, int *K)
char * WriteExponent(int K, char *buffer)
int CountDecimalDigit32(uint32_t n)
const GenericPointer< typename T::ValueType > T2 value
void NormalizedBoundaries(DiyFp *minus, DiyFp *plus) const
DiyFp GetCachedPower(int e, int *K)
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)