dtoa.h#
Functions to format floating point numbers. Header for the library by David M. Gay.
Authors#
TheSilvered
Functions#
Nst_dtoa#
Synopsis:
char *Nst_dtoa(f64 value, int mode, int n_digits, int *decimal_point,
int *sign, char **str_end)
Description:
Convert a double to an ASCII string.
Modes:
0: shortest string that yieldsvaluewhen read in and rounded to nearest.1: like 0, but with Steele & White stopping rule; e.g. with IEEE P754 arithmetic, mode0gives1e23whereas mode1gives 9.999999999999999e22`.2:max(1, n_digits)significant digits; this gives a return value similar to that ofecvt, except that trailing zeros are suppressed.3: throughn_digitspast the decimal point; this gives a return value similar to that fromfcvt, except that trailing zeros are suppressed, andn_digitscan be negative.4,5: similar to2and3, respectively, but (in round-nearest mode) with the tests of mode0to possibly return a shorter string that rounds tovalue.6through9: Debugging modes similar to mode - 4: don't try fast floating-point estimate (if applicable).
Parameters:
value: the double to convertmode: the mode to use to convert the number, valid modes range fromn_digits: the number of digits to output, the specific amount varies in regards to themodeuseddecimal_point: pointer where to place the position of the decimal point relative to the string of digits returned, it is set to9999ifvalueis NaN or Infinitysign: set to0for positive values and to1for negative values, it is ignored if set toNULLstr_end: a pointer set to the end of the returned string, it is ignored if set toNULL
Returns:
An allocated string of digits where trailing zeroes are suppressed. This value
must be freed with Nst_freedtoa.
Nst_freedtoa#
Synopsis:
void Nst_freedtoa(char *str)
Description:
Free a string returned by Nst_dtoa.
Nst_strtod#
Synopsis:
f64 Nst_strtod(const char *str, char **str_end)
Description:
Convert a string to a double.
This function works like
strtod in the C
standard.
Parameters:
str: the string to convertstr_end: pointer set to the character after the last digit of the parsed number, it is ignored if set toNULL
Returns:
The parsed number.