decimal¶
A decimal is a decimal number of arbitrary precision, but this implementation only supports values that fit in a double.
Unlike double, decimal is written in numeric form, never in scientific notation. Special infinity and NaN values aren’t supported. Note that the decimal representation for some numbers is very long, so double may be a better choice for values in a wide range.
Canonical form has no leading “+” sign, and at most 1 leading or trailing zero such that there is at least 1 digit on either side of the decimal point, like “12.34”, “-1.0”, and “0.0”.
Non-canonical form allows a leading “+”, any number of leading and trailing zeros, any number of digits (including zero) on either side of the point, and doesn’t require a decimal point, like “+1”, “01”, “-.5”, “4.”, and “42”.
-
ExessVariableResult exess_read_decimal(const char *str, size_t out_size, void *out)¶
Read a
decimalstring after any leading whitespace.The high-precision value format is opaque to the user, but can be written or converted to other types.
- Parameters:
str – String to read.
out_size – Size of
outin bytes.out – Parsed value.
- Returns:
The
read_countof characters read,write_countof bytes written, and astatus. Thestatuswill beExessStatus.EXESS_LOSSif an approximate value was successfully read by dropping significant digits.
-
ExessResult exess_write_decimal(size_t value_size, const void *value, size_t buf_size, char *buf)¶
Write a canonical
decimalstring.- Parameters:
value_size – The size of
valuein bytes.value – Value to write.
buf_size – Size of
bufin bytes.buf – Output buffer, or null to only measure.
- Returns:
The
countof characters in the output, and astatus(ExessStatus.EXESS_SUCCESS, orExessStatus.EXESS_NO_SPACEif the buffer is too small).