23 #ifndef RAPIDJSON_DTOA_ 24 #define RAPIDJSON_DTOA_ 35 RAPIDJSON_DIAG_OFF(effc++)
36 RAPIDJSON_DIAG_OFF(array - bounds)
42 while (rest < wp_w && delta - rest >= ten_kappa &&
43 (rest + ten_kappa < wp_w ||
44 wp_w - rest > rest + ten_kappa - wp_w)) {
54 if (n < 100)
return 2;
55 if (n < 1000)
return 3;
56 if (n < 10000)
return 4;
57 if (n < 100000)
return 5;
58 if (n < 1000000)
return 6;
59 if (n < 10000000)
return 7;
60 if (n < 100000000)
return 8;
68 char *buffer,
int *len,
int *K) {
69 static const uint32_t kPow10[] = {1, 10, 100, 1000,
70 10000, 100000, 1000000, 10000000,
71 100000000, 1000000000};
73 const DiyFp wp_w = Mp - W;
121 buffer[(*len)++] =
static_cast<char>(
'0' +
static_cast<char>(d));
127 static_cast<uint64_t>(kPow10[kappa]) << -one.
e, wp_w.
f);
136 char d =
static_cast<char>(p2 >> -one.
e);
137 if (d || *len) buffer[(*len)++] =
static_cast<char>(
'0' + d);
144 wp_w.
f * (index < 9 ? kPow10[index] : 0));
150 inline void Grisu2(
double value,
char *buffer,
int *length,
int *K) {
151 const DiyFp v(value);
157 DiyFp Wp = w_p * c_mk;
158 DiyFp Wm = w_m * c_mk;
161 DigitGen(W, Wp, Wp.
f - Wm.
f, buffer, length, K);
171 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K / 100));
176 }
else if (K >= 10) {
181 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K));
186 inline char *
Prettify(
char *buffer,
int length,
int k,
int maxDecimalPlaces) {
187 const int kk = length + k;
189 if (0 <= k && kk <= 21) {
191 for (
int i = length; i < kk; i++) buffer[i] =
'0';
193 buffer[kk + 1] =
'0';
194 return &buffer[kk + 2];
195 }
else if (0 < kk && kk <= 21) {
197 std::memmove(&buffer[kk + 1], &buffer[kk],
198 static_cast<size_t>(length - kk));
200 if (0 > k + maxDecimalPlaces) {
203 for (
int i = kk + maxDecimalPlaces; i > kk + 1; i--)
204 if (buffer[i] !=
'0')
return &buffer[i + 1];
205 return &buffer[kk + 2];
207 return &buffer[length + 1];
208 }
else if (-6 < kk && kk <= 0) {
210 const int offset = 2 - kk;
211 std::memmove(&buffer[offset], &buffer[0], static_cast<size_t>(length));
214 for (
int i = 2; i < offset; i++) buffer[i] =
'0';
215 if (length - kk > maxDecimalPlaces) {
218 for (
int i = maxDecimalPlaces + 1; i > 2; i--)
219 if (buffer[i] !=
'0')
return &buffer[i + 1];
222 return &buffer[length + offset];
223 }
else if (kk < -maxDecimalPlaces) {
229 }
else if (length == 1) {
235 std::memmove(&buffer[2], &buffer[1], static_cast<size_t>(length - 1));
237 buffer[length + 1] =
'e';
242 inline char *
dtoa(
double value,
char *buffer,
int maxDecimalPlaces = 324) {
246 if (d.
Sign()) *buffer++ =
'-';
257 Grisu2(value, buffer, &length, &K);
258 return Prettify(buffer, length, K, maxDecimalPlaces);
269 #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
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
void NormalizedBoundaries(DiyFp *minus, DiyFp *plus) const
DiyFp GetCachedPower(int e, int *K)
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)