CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Internal conversion functions

Macros

#define STRNUM_INTBUF   66
 Buffer size for integer-to-string conversion (64-bit binary + sign + null terminator)
 
#define STRNUM_FPDIGITS   18
 Maximum meaningful floating-point digits (53-bit mantissa precision)
 
#define STRNUM_FPBUF   25
 Buffer size for floating-point-to-string conversion (sign + digits + exponent + null)
 

Functions

uint8 * _strnum_u64toa (uint8 buf[STRNUM_INTBUF], uint32 *len, uint64 value, uint16 base, uint32 mindigits, char sign, bool upper)
 
uint32 _strnum_f64toa (float64 d, uint8 dest[STRNUM_FPBUF])
 
uint32 _strnum_f32toa (float32 f, uint8 dest[STRNUM_FPBUF])
 
int32 _strnum_grisu2_32 (float32 f, uint8 *digits, int32 *K)
 
int32 _strnum_grisu2_64 (float64 d, uint8 *digits, int32 *K)
 

Detailed Description

Low-level helpers used by the format module and other internal components. They work with fixed-size buffers and return raw digit arrays. Most code should use the higher-level str* functions above.

Function Documentation

◆ _strnum_f32toa()

uint32 _strnum_f32toa ( float32  f,
uint8  dest[STRNUM_FPBUF] 
)

Converts a 32-bit float to ASCII string

Like _strnum_f64toa(), but for single-precision floats.

Parameters
fFloat value to convert
destBuffer to write result (STRNUM_FPBUF bytes)
Returns
Length of resulting string (excluding null terminator)

◆ _strnum_f64toa()

uint32 _strnum_f64toa ( float64  d,
uint8  dest[STRNUM_FPBUF] 
)

Converts a 64-bit float to ASCII string

Internal function using Grisu2 algorithm. Automatically selects format (plain, decimal, or scientific notation) and handles special values.

Parameters
dDouble value to convert
destBuffer to write result (STRNUM_FPBUF bytes)
Returns
Length of resulting string (excluding null terminator)

◆ _strnum_grisu2_32()

int32 _strnum_grisu2_32 ( float32  f,
uint8 *  digits,
int32 *  K 
)

Low-level Grisu2 algorithm for 32-bit float

Extracts decimal digits and exponent for a float. This is the core of the Grisu2 algorithm and is used internally by _strnum_f32toa().

Parameters
fFloat value to convert
digitsBuffer to receive decimal digits (no decimal point, 18 bytes)
KPointer to exponent value (input/output)
Returns
Number of significant digits written to the digits buffer

◆ _strnum_grisu2_64()

int32 _strnum_grisu2_64 ( float64  d,
uint8 *  digits,
int32 *  K 
)

Low-level Grisu2 algorithm for 64-bit double

Like _strnum_grisu2_32(), but for double-precision values.

Parameters
dDouble value to convert
digitsBuffer to receive decimal digits (no decimal point, 18 bytes)
KPointer to exponent value (input/output)
Returns
Number of significant digits written to the digits buffer

◆ _strnum_u64toa()

uint8 * _strnum_u64toa ( uint8  buf[STRNUM_INTBUF],
uint32 *  len,
uint64  value,
uint16  base,
uint32  mindigits,
char  sign,
bool  upper 
)

Converts a 64-bit unsigned integer to ASCII digits

Internal function for integer formatting. Converts the value to the specified base and writes ASCII digits into the provided buffer, returning a pointer to the start of the converted string within the buffer.

Parameters
bufFixed-size buffer (STRNUM_INTBUF bytes) to write into
lenOptional pointer to receive the length of the result (excluding null terminator)
valueValue to convert
baseNumeric base (2-36)
mindigitsMinimum number of digits (zero-padded if necessary)
signSign character to prepend (0 for none, '-' or '+' typically)
upperIf true, use uppercase letters for bases > 10; if false, use lowercase
Returns
Pointer into buf where the converted string starts (null-terminated)