19 #ifndef RAPIDJSON_DTOA_
20 #define RAPIDJSON_DTOA_
31 RAPIDJSON_DIAG_OFF(effc++)
35 while (rest < wp_w && delta - rest >= ten_kappa &&
36 (rest + ten_kappa < wp_w ||
37 wp_w - rest > rest + ten_kappa - wp_w)) {
46 if (n < 100)
return 2;
47 if (n < 1000)
return 3;
48 if (n < 10000)
return 4;
49 if (n < 100000)
return 5;
50 if (n < 1000000)
return 6;
51 if (n < 10000000)
return 7;
52 if (n < 100000000)
return 8;
60 static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
62 const DiyFp wp_w = Mp - W;
71 case 9: d = p1 / 100000000; p1 %= 100000000;
break;
72 case 8: d = p1 / 10000000; p1 %= 10000000;
break;
73 case 7: d = p1 / 1000000; p1 %= 1000000;
break;
74 case 6: d = p1 / 100000; p1 %= 100000;
break;
75 case 5: d = p1 / 10000; p1 %= 10000;
break;
76 case 4: d = p1 / 1000; p1 %= 1000;
break;
77 case 3: d = p1 / 100; p1 %= 100;
break;
78 case 2: d = p1 / 10; p1 %= 10;
break;
79 case 1: d = p1; p1 = 0;
break;
83 buffer[(*len)++] =
static_cast<char>(
'0' +
static_cast<char>(d));
88 GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.
e, wp_w.
f);
97 char d =
static_cast<char>(p2 >> -one.
e);
99 buffer[(*len)++] =
static_cast<char>(
'0' + d);
104 GrisuRound(buffer, *len, delta, p2, one.
f, wp_w.
f * kPow10[-kappa]);
111 const DiyFp v(value);
117 DiyFp Wp = w_p * c_mk;
118 DiyFp Wm = w_m * c_mk;
121 DigitGen(W, Wp, Wp.
f - Wm.
f, buffer, length, K);
131 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K / 100));
143 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K));
149 const int kk = length + k;
151 if (length <= kk && kk <= 21) {
153 for (
int i = length; i < kk; i++)
156 buffer[kk + 1] =
'0';
157 return &buffer[kk + 2];
159 else if (0 < kk && kk <= 21) {
161 std::memmove(&buffer[kk + 1], &buffer[kk], length - kk);
163 return &buffer[length + 1];
165 else if (-6 < kk && kk <= 0) {
167 const int offset = 2 - kk;
168 std::memmove(&buffer[offset], &buffer[0], length);
171 for (
int i = 2; i < offset; i++)
173 return &buffer[length + offset];
175 else if (length == 1) {
182 std::memmove(&buffer[2], &buffer[1], length - 1);
184 buffer[length + 1] =
'e';
205 Grisu2(value, buffer, &length, &K);
217 #endif // RAPIDJSON_DTOA_
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
char * Prettify(char *buffer, int length, int k)
Definition: dtoa.h:148
unsigned CountDecimalDigit32(uint32_t n)
Definition: dtoa.h:43
const char * GetDigitsLut()
Definition: itoa.h:23
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
DiyFp Normalize() const
Definition: diyfp.h:95
bool Sign() const
Definition: ieee754.h:37
static unorm16 one()
Definition: unorm16.h:78
unsigned int uint32_t
Definition: stdint.h:80
void Grisu2(double value, char *buffer, int *length, int *K)
Definition: dtoa.h:110
bool IsZero() const
Definition: ieee754.h:44
void GrisuRound(char *buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w)
Definition: dtoa.h:34
unsigned __int64 uint64_t
Definition: stdint.h:90
uint64_t f
Definition: diyfp.h:154
void DigitGen(const DiyFp &W, const DiyFp &Mp, uint64_t delta, char *buffer, int *len, int *K)
Definition: dtoa.h:59
char * WriteExponent(int K, char *buffer)
Definition: dtoa.h:124
float length(float v)
Definition: vectorMath.h:208
char * dtoa(double value, char *buffer)
Definition: dtoa.h:189
Definition: document.h:390
int e
Definition: diyfp.h:155
const FieldDescriptor value
Definition: descriptor.h:1522
void NormalizedBoundaries(DiyFp *minus, DiyFp *plus) const
Definition: diyfp.h:124
DiyFp GetCachedPower(int e, int *K)
Definition: diyfp.h:220