unlocalized.h
Include dependency graph for unlocalized.h:
This graph shows which files directly or indirectly include unlocalized.h:
Locale-independent functions for floating-point numbers.
Provides formatting and parsing of floating-point numbers that always use ‘.’ as the decimal separator regardless of LC_NUMERIC. Thread-safe when snprintf_l()/strtod_l() or uselocale() is available. On pure C99 platforms, best-effort assuming no concurrent setlocale().
Defines
-
UNLOCALIZED_ENABLE_DOUBLE_API
Functions
-
int unlocalized_snprintf(char *buf, size_t size, const char *fmt, ...)
Locale-independent snprintf.
Behaves like snprintf but always uses ‘.’ as decimal separator regardless of LC_NUMERIC for floating-point conversions.
-
bool unlocalized_validate_bare_float_format(const char buf[], size_t len)
Validate strict bare decimal float format.
Checks that buf[0..len-1] matches the grammar: [+|-] DIGITS “.” DIGITS [(“e”|”E”) [+|-] DIGITS] where DIGITS is one or more ‘0’-‘9’ characters.
Rejects hex floats, inf, nan, whitespace, commas, and any other characters not in the grammar.
- Parameters:
buf – pointer to the character data (need not be null-terminated)
len – number of characters to validate
- Returns:
true if the format is valid, false otherwise
-
int unlocalized_strtod(const char buf[], size_t len, double *result)
Parse a double from a string locale-independently with strict validation.
Validates the input against the bare float format (see unlocalized_validate_bare_float_format), then parses with strtod using ‘.’ as decimal separator regardless of LC_NUMERIC. Rejects overflow (inf) but allows underflow (returns 0.0).
- Parameters:
buf – pointer to the character data (need not be null-terminated)
len – number of characters to parse (max 255)
result – [out] on success, the parsed double value
- Returns:
0 on success, -1 on error (caller should raise badarg)
-
static inline int unlocalized_strto_avm_float(const char buf[], size_t len, avm_float_t *result)
Parse an avm_float_t from a string locale-independently.
Dispatches to unlocalized_strtod or unlocalized_strtof depending on AVM_USE_SINGLE_PRECISION.