dconv 2.0
C++14 library for printing and parsing floating point numbers
Loading...
Searching...
No Matches
dconv::grisu3 Namespace Reference

Functions

bool roundWeed (char *buffer, int length, uint64_t wpW, uint64_t delta, uint64_t rest, uint64_t tenKappa, uint64_t ulp) noexcept
 round the last digit to the closest value and check it is safe.
 
bool digitsGen (const DiyFp &low, const DiyFp &w, const DiyFp &high, char *buffer, int &length, int &k) noexcept
 generate the shortest digits within the liberal boundaries.
 
void fallback (char *buffer, int &length, int &k, double value) noexcept
 write the shortest and closest decimal digits using the standard library.
 
void generate (char *buffer, int &length, int &k, double value) noexcept
 write the shortest and closest decimal digits.
 
char * dtoa (char *buffer, double value) noexcept
 double to string conversion using Grisu3.
 

Function Documentation

◆ digitsGen()

bool dconv::grisu3::digitsGen ( const DiyFp & low,
const DiyFp & w,
const DiyFp & high,
char * buffer,
int & length,
int & k )
inlinenoexcept

generate the shortest digits within the liberal boundaries.

Parameters
lowlower boundary.
wvalue.
highupper boundary.
bufferbuffer to write the digits to.
lengthnumber of digits written.
kdecimal exponent.
Returns
true if the digits are the shortest and closest, false otherwise.

◆ dtoa()

char * dconv::grisu3::dtoa ( char * buffer,
double value )
inlinenoexcept

double to string conversion using Grisu3.

Parameters
bufferbuffer to write the string representation to (must point to at least 25 writable bytes).
valuevalue to convert.
Returns
end position.

◆ fallback()

void dconv::grisu3::fallback ( char * buffer,
int & length,
int & k,
double value )
inlinenoexcept

write the shortest and closest decimal digits using the standard library.

Parameters
bufferbuffer to write the digits to.
lengthnumber of digits written.
kdecimal exponent.
valuepositive value to convert.

◆ generate()

void dconv::grisu3::generate ( char * buffer,
int & length,
int & k,
double value )
inlinenoexcept

write the shortest and closest decimal digits.

Parameters
bufferbuffer to write the digits to.
lengthnumber of digits written.
kdecimal exponent.
valuepositive value to convert.

◆ roundWeed()

bool dconv::grisu3::roundWeed ( char * buffer,
int length,
uint64_t wpW,
uint64_t delta,
uint64_t rest,
uint64_t tenKappa,
uint64_t ulp )
inlinenoexcept

round the last digit to the closest value and check it is safe.

Parameters
buffergenerated digits.
lengthnumber of generated digits.
wpWdistance between the liberal upper boundary and the value.
deltaliberal interval size.
restdistance between the liberal upper boundary and the generated number.
tenKappascaled power of ten of the last digit.
ulpscaled unit of the approximation error.
Returns
true if the generated number is the shortest and closest, false otherwise.