25#ifndef __DCONV_GRISU_HPP__
26#define __DCONV_GRISU_HPP__
50 inline char*
dtoa (
char* buffer,
double value,
51 void (*
generate) (
char*,
int&,
int&,
double)
noexcept)
noexcept
54 memcpy (&bits, &value,
sizeof (
double));
55 bool is_negative = (bits >> 63) != 0;
58 buffer += is_negative;
59 value = is_negative ? -value : value;
63 memcpy (buffer,
"0.0", 3);
67 int length = 0, k = 0;
81 const int expr = -59 - (exponent + 64) + 63;
82 const int mk = (expr * 30103 + 99999) / 100000;
84 assert (mk + 343 >= 0 && mk + 343 < 687);
96 inline void generate (
char* buffer,
int& length,
int& k,
double value)
noexcept
113 while ((length < 18) && (part2 != 0))
116 buffer[length++] =
static_cast<char> (
'0' + (part2 >> -one.
_exponent));
128 inline char*
dtoa (
char* buffer,
double value)
noexcept
hand made floating point.
Definition diyfp.hpp:41
constexpr DiyFp & normalize() noexcept
normalize floating point.
Definition diyfp.hpp:104
uint64_t _mantissa
mantissa.
Definition diyfp.hpp:223
int _exponent
exponent.
Definition diyfp.hpp:226
constexpr uint32_t pow10[]
powers of ten that fit in 32 bits.
Definition digits.hpp:36
char * prettify(char *buffer, int length, int k) noexcept
lay out decimal digits as a fixed or scientific number.
Definition format.hpp:76
int countDigits(uint64_t digits) noexcept
count the digits of a decimal significand.
Definition digits.hpp:64
constexpr DiyFp grisupow[]
cached powers of ten for the grisu algorithms.
Definition grisupow.hpp:36
char * dtoa(char *buffer, double value, void(*generate)(char *, int &, int &, double) noexcept) noexcept
double to string conversion with the given digits generator.
Definition grisu.hpp:50
const DiyFp & cachedPower(int exponent, int &k) noexcept
get the cached power of ten that scales a binary exponent into the digit generation range.
Definition grisu.hpp:79
void generate(char *buffer, int &length, int &k, double value) noexcept
write the decimal digits of the scaled value.
Definition grisu.hpp:96
char * dtoa(char *buffer, double value) noexcept
double to string conversion using Grisu.
Definition grisu.hpp:128