56inline int modp_dtoa(
double value,
char* str,
int prec) {
57 static const double pow10[] = {1, 10, 100, 1000,
58 10000, 100000, 1000000, 10000000,
59 100000000, 1000000000};
66 if (!(value == value)) {
75 const double thres_max = (double)(0x7FFFFFFF);
82 }
else if (prec > 9) {
95 int whole = (int)value;
96 double tmp = (value - whole) * pow10[prec];
97 uint32_t frac = (uint32_t)(tmp);
103 if (frac >= pow10[prec]) {
107 }
else if (diff == 0.5 && ((frac == 0) || (frac & 1))) {
119 if (value > thres_max) {
120 return sprintf(str,
"%e", neg ? -value : value);
124 diff = value - whole;
128 }
else if (diff == 0.5 && (whole & 1)) {
138 *wstr++ = (char)(48 + (frac % 10));
139 }
while (frac /= 10);
141 while (count-- > 0) *wstr++ =
'0';
149 do *wstr++ = (char)(48 + (whole % 10));