20#ifndef RAPIDJSON_DTOA_
21#define RAPIDJSON_DTOA_
32RAPIDJSON_DIAG_OFF(effc++)
33RAPIDJSON_DIAG_OFF(array-bounds)
37 while (rest < wp_w && delta - rest >= ten_kappa &&
38 (rest + ten_kappa < wp_w ||
39 wp_w - rest > rest + ten_kappa - wp_w)) {
45inline int CountDecimalDigit32(
uint32_t n) {
48 if (n < 100)
return 2;
49 if (n < 1000)
return 3;
50 if (n < 10000)
return 4;
51 if (n < 100000)
return 5;
52 if (n < 1000000)
return 6;
53 if (n < 10000000)
return 7;
54 if (n < 100000000)
return 8;
61inline void DigitGen(
const DiyFp& W,
const DiyFp& Mp,
uint64_t delta,
char* buffer,
int* len,
int* K) {
62 static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
63 const DiyFp one(
uint64_t(1) << -Mp.e, Mp.e);
64 const DiyFp wp_w = Mp - W;
67 int kappa = CountDecimalDigit32(p1);
73 case 9: d = p1 / 100000000; p1 %= 100000000;
break;
74 case 8: d = p1 / 10000000; p1 %= 10000000;
break;
75 case 7: d = p1 / 1000000; p1 %= 1000000;
break;
76 case 6: d = p1 / 100000; p1 %= 100000;
break;
77 case 5: d = p1 / 10000; p1 %= 10000;
break;
78 case 4: d = p1 / 1000; p1 %= 1000;
break;
79 case 3: d = p1 / 100; p1 %= 100;
break;
80 case 2: d = p1 / 10; p1 %= 10;
break;
81 case 1: d = p1; p1 = 0;
break;
85 buffer[(*len)++] =
static_cast<char>(
'0' +
static_cast<char>(d));
90 GrisuRound(buffer, *len, delta, tmp,
static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
99 char d =
static_cast<char>(p2 >> -one.e);
101 buffer[(*len)++] =
static_cast<char>(
'0' + d);
107 GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0));
113inline void Grisu2(
double value,
char* buffer,
int* length,
int* K) {
114 const DiyFp v(value);
116 v.NormalizedBoundaries(&w_m, &w_p);
118 const DiyFp c_mk = GetCachedPower(w_p.e, K);
119 const DiyFp W = v.Normalize() * c_mk;
120 DiyFp Wp = w_p * c_mk;
121 DiyFp Wm = w_m * c_mk;
124 DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
127inline char* WriteExponent(
int K,
char* buffer) {
134 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K / 100));
136 const char* d = GetDigitsLut() + K * 2;
141 const char* d = GetDigitsLut() + K * 2;
146 *buffer++ =
static_cast<char>(
'0' +
static_cast<char>(K));
151inline char* Prettify(
char* buffer,
int length,
int k,
int maxDecimalPlaces) {
152 const int kk = length + k;
154 if (0 <= k && kk <= 21) {
156 for (
int i = length; i < kk; i++)
159 buffer[kk + 1] =
'0';
160 return &buffer[kk + 2];
162 else if (0 < kk && kk <= 21) {
164 std::memmove(&buffer[kk + 1], &buffer[kk],
static_cast<size_t>(length - kk));
166 if (0 > k + maxDecimalPlaces) {
169 for (
int i = kk + maxDecimalPlaces; i > kk + 1; i--)
170 if (buffer[i] !=
'0')
171 return &buffer[i + 1];
172 return &buffer[kk + 2];
175 return &buffer[length + 1];
177 else if (-6 < kk && kk <= 0) {
179 const int offset = 2 - kk;
180 std::memmove(&buffer[offset], &buffer[0],
static_cast<size_t>(length));
183 for (
int i = 2; i < offset; i++)
185 if (length - kk > maxDecimalPlaces) {
188 for (
int i = maxDecimalPlaces + 1; i > 2; i--)
189 if (buffer[i] !=
'0')
190 return &buffer[i + 1];
194 return &buffer[length + offset];
196 else if (kk < -maxDecimalPlaces) {
203 else if (length == 1) {
206 return WriteExponent(kk - 1, &buffer[2]);
210 std::memmove(&buffer[2], &buffer[1],
static_cast<size_t>(length - 1));
212 buffer[length + 1] =
'e';
213 return WriteExponent(kk - 1, &buffer[0 + length + 2]);
217inline char* dtoa(
double value,
char* buffer,
int maxDecimalPlaces = 324) {
234 Grisu2(value, buffer, &length, &K);
235 return Prettify(buffer, length, K, maxDecimalPlaces);
Lecteur des fichiers de maillage via la bibliothèque LIMA.
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Integer len(const char *s)
Retourne la longueur de la chaîne s.