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 decimal string 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 out in bytes.

  • out – Parsed value.

Returns:

The read_count of characters read, write_count of bytes written, and a status. The status will be ExessStatus.EXESS_LOSS if 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 decimal string.

Parameters:
  • value_size – The size of value in bytes.

  • value – Value to write.

  • buf_size – Size of buf in bytes.

  • buf – Output buffer, or null to only measure.

Returns:

The count of characters in the output, and a status (ExessStatus.EXESS_SUCCESS, or ExessStatus.EXESS_NO_SPACE if the buffer is too small).