25#ifndef JOIN_DATA_DTOA_HPP
26#define JOIN_DATA_DTOA_HPP
46 *buffer++ =
'0' + k / 100;
48 *buffer++ =
'0' + k / 10;
53 *buffer++ =
'0' + k / 10;
60 inline char*
prettify (
char* buffer,
int length,
int k)
noexcept
63 const int kk = length + k;
65 if ((length <= kk) && (kk <= 21))
67 memset (buffer + length,
'0', kk - length);
70 return &buffer[kk + 2];
72 else if ((0 < kk) && (kk <= 21))
74 memmove (&buffer[kk + 1], &buffer[kk], length - kk);
76 return &buffer[length + 1];
78 else if ((-6 < kk) && (kk <= 0))
81 memmove (&buffer[offset], &buffer[0], length);
84 memset (&buffer[2],
'0', offset - 2);
85 return &buffer[length + offset];
94 memmove (&buffer[2], &buffer[1], length - 1);
96 buffer[length + 1] =
'e';
101 inline void grisuRound (
char* buffer,
int length, uint64_t delta, uint64_t rest, uint64_t ten_kappa,
102 uint64_t wp_w)
noexcept
104 while ((rest < wp_w && delta - rest >= ten_kappa) &&
105 (rest + ten_kappa < wp_w || wp_w - rest > rest + ten_kappa - wp_w))
107 --buffer[length - 1];
138 const DiyFp one (
static_cast<uint64_t
> (1) << -Mp._exponent, Mp._exponent);
139 const DiyFp wp_w = Mp - W;
140 uint32_t p1 =
static_cast<uint32_t
> (Mp._mantissa >> -one.
_exponent);
147 assert (kappa >= 1 && kappa <= 10);
148 uint32_t d = p1 /
pow10[kappa - 1];
149 p1 %=
pow10[kappa - 1];
152 buffer[length++] =
'0' + d;
155 uint64_t tmp = (
static_cast<uint64_t
> (p1) << -one.
_exponent) + p2;
168 assert (unit <= UINT64_MAX / 10);
172 char d =
static_cast<char> (p2 >> -one.
_exponent);
175 buffer[length++] =
'0' + d;
188 inline void grisu2 (
char* buffer,
int& length,
int& k,
double value)
noexcept
190 DiyFp val (value), minus, plus;
193 const int expr = -59 - (plus.
_exponent + 64) + 63;
194 const int mk = (expr * 30103 + 99999) / 100000;
196 assert (mk + 343 >= 0 && mk + 343 < 687);
216 inline char*
dtoa (
char* buffer,
double value)
noexcept
219 memcpy (&bits, &value,
sizeof (
double));
220 bool is_negative = (bits >> 63) != 0;
223 buffer += is_negative;
224 value = is_negative ? -value : value;
228 memcpy (buffer,
"0.0", 3);
232 int length = 0, k = 0;
hand made floating point.
Definition diyfp.hpp:42
int _exponent
exponent.
Definition diyfp.hpp:227
uint64_t _mantissa
mantissa.
Definition diyfp.hpp:224
constexpr void normalizedBoundaries(DiyFp &minus, DiyFp &plus) const noexcept
get normalized boundaries.
Definition diyfp.hpp:148
char * prettify(char *buffer, int length, int k) noexcept
Definition dtoa.hpp:60
void digitsGen(const DiyFp &W, const DiyFp &Mp, uint64_t delta, char *buffer, int &length, int &k) noexcept
Definition dtoa.hpp:135
constexpr int digitsCount(uint32_t n) noexcept
Definition dtoa.hpp:112
char * writeExponent(char *buffer, int k) noexcept
Definition dtoa.hpp:39
constexpr DiyFp dtoapow[]
Definition dtoapow.hpp:37
void grisu2(char *buffer, int &length, int &k, double value) noexcept
Definition dtoa.hpp:188
constexpr uint32_t pow10[]
Definition dtoapow.hpp:35
void grisuRound(char *buffer, int length, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) noexcept
Definition dtoa.hpp:101
Definition acceptor.hpp:32
char * dtoa(char *buffer, double value) noexcept
double to string conversion.
Definition dtoa.hpp:216