Numbers libraryNumbers.h
The Numbers library scans C style string for number values in different numeral systems, and converts them to internal computer format, depending of expected data types. The library checks integer overflow and underflow conditions and signals to caller if such situation has occurred. The functions don't use local decimal mark to separate integer and fractional parts. They use only point symbol ('.') as the default decimal mark.
These functions were made as replacement for standard C library string conversion functions, and may be useful in programs that do intensive numbers extraction from any strings representations: binary, octal, decimal and hexadecimal. They are extremely fast, especially for floating-point numbers. See the benchmarks.
Contents
Function list
C function name | Functions | C++ function name | Functions |
---|---|---|---|
BinToNum | 9 functions | BinToNum | 9 functions |
DecToNum | 11 functions | DecToNum | 11 functions |
HexToNum | 11 functions | HexToNum | 11 functions |
OctToNum | 9 functions | OctToNum | 9 functions |
C function name | Functions | C++ function name | Functions |
Binary numbers conversion
C Unsigned integer types size_t Numbers_BinToNum_uint8 (uint8_t *number, const char8_t string[]); size_t Numbers_BinToNum_uint16 (uint16_t *number, const char8_t string[]); size_t Numbers_BinToNum_uint32 (uint32_t *number, const char8_t string[]); size_t Numbers_BinToNum_uint64 (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers_BinToNum_sint8 (sint8_t *number, const char8_t string[]); size_t Numbers_BinToNum_sint16 (sint16_t *number, const char8_t string[]); size_t Numbers_BinToNum_sint32 (sint32_t *number, const char8_t string[]); size_t Numbers_BinToNum_sint64 (sint64_t *number, const char8_t string[]); Other types size_t Numbers_BinToNum_size (size_t *number, const char8_t string[]);
C++ Unsigned integer types size_t Numbers::BinToNum (uint8_t *number, const char8_t string[]); size_t Numbers::BinToNum (uint16_t *number, const char8_t string[]); size_t Numbers::BinToNum (uint32_t *number, const char8_t string[]); size_t Numbers::BinToNum (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers::BinToNum (sint8_t *number, const char8_t string[]); size_t Numbers::BinToNum (sint16_t *number, const char8_t string[]); size_t Numbers::BinToNum (sint32_t *number, const char8_t string[]); size_t Numbers::BinToNum (sint64_t *number, const char8_t string[]); Other types size_t Numbers::BinToNum (size_t *number, const char8_t string[]);
Description: Convert number in binary format, with possibly preceding "0b" prefix, to internal computer format, depending of expected data type.
Parameters:
- number - pointer to a variable where number value should be placed
- string - pointer to string where binary number may be found
Return value:
- Count of characters (not bytes), including preceding white symbols, which were read and converted.
- -1 if no number is found.
- 0 (zero) if overflow is occurred during number conversion.
Octal numbers conversion
C Unsigned integer types size_t Numbers_OctToNum_uint8 (uint8_t *number, const char8_t string[]); size_t Numbers_OctToNum_uint16 (uint16_t *number, const char8_t string[]); size_t Numbers_OctToNum_uint32 (uint32_t *number, const char8_t string[]); size_t Numbers_OctToNum_uint64 (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers_OctToNum_sint8 (sint8_t *number, const char8_t string[]); size_t Numbers_OctToNum_sint16 (sint16_t *number, const char8_t string[]); size_t Numbers_OctToNum_sint32 (sint32_t *number, const char8_t string[]); size_t Numbers_OctToNum_sint64 (sint64_t *number, const char8_t string[]); Other types size_t Numbers_OctToNum_size (size_t *number, const char8_t string[]);
C++ Unsigned integer types size_t Numbers::OctToNum (uint8_t *number, const char8_t string[]); size_t Numbers::OctToNum (uint16_t *number, const char8_t string[]); size_t Numbers::OctToNum (uint32_t *number, const char8_t string[]); size_t Numbers::OctToNum (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers::OctToNum (sint8_t *number, const char8_t string[]); size_t Numbers::OctToNum (sint16_t *number, const char8_t string[]); size_t Numbers::OctToNum (sint32_t *number, const char8_t string[]); size_t Numbers::OctToNum (sint64_t *number, const char8_t string[]); Other types size_t Numbers::OctToNum (size_t *number, const char8_t string[]);
Description: Convert number in octal format, ignoring preceding "0" digits, to internal computer format, depending of expected data type.
Parameters:
- number - pointer to a variable where number value should be placed
- string - pointer to string where octal number may be found
Return value:
- Count of characters (not bytes), including preceding white symbols, which were read and converted.
- -1 if no number is found.
- 0 (zero) if overflow is occurred during number conversion.
Hexadecimal numbers conversion
C Unsigned integer types size_t Numbers_HexToNum_uint8 (uint8_t *number, const char8_t string[]); size_t Numbers_HexToNum_uint16 (uint16_t *number, const char8_t string[]); size_t Numbers_HexToNum_uint32 (uint32_t *number, const char8_t string[]); size_t Numbers_HexToNum_uint64 (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers_HexToNum_sint8 (sint8_t *number, const char8_t string[]); size_t Numbers_HexToNum_sint16 (sint16_t *number, const char8_t string[]); size_t Numbers_HexToNum_sint32 (sint32_t *number, const char8_t string[]); size_t Numbers_HexToNum_sint64 (sint64_t *number, const char8_t string[]); Floating-point types size_t Numbers_HexToNum_flt32 (flt32_t *number, const char8_t string[]); size_t Numbers_HexToNum_flt32 (flt64_t *number, const char8_t string[]); Other types size_t Numbers_HexToNum_size (size_t *number, const char8_t string[]);
C++ Unsigned integer types size_t Numbers::HexToNum (uint8_t *number, const char8_t string[]); size_t Numbers::HexToNum (uint16_t *number, const char8_t string[]); size_t Numbers::HexToNum (uint32_t *number, const char8_t string[]); size_t Numbers::HexToNum (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers::HexToNum (sint8_t *number, const char8_t string[]); size_t Numbers::HexToNum (sint16_t *number, const char8_t string[]); size_t Numbers::HexToNum (sint32_t *number, const char8_t string[]); size_t Numbers::HexToNum (sint64_t *number, const char8_t string[]); Floating-point types size_t Numbers::HexToNum (flt32_t *number, const char8_t string[]); size_t Numbers::HexToNum (flt64_t *number, const char8_t string[]); Other types size_t Numbers::HexToNum (size_t *number, const char8_t string[]);
Description: Convert number in hexadecimal format, with possibly preceding "0x" prefix, to internal computer format, depending of expected data type.
Parameters:
- number - pointer to a variable where number value should be placed
- string - pointer to string where hexadecimal number may be found
Return value:
- Count of characters (not bytes), including preceding white symbols, which were read and converted.
- -1 if no number is found.
- 0 (zero) if overflow is occurred during integer number conversion, or exponent overflow is occurred dufing floating-point number conversion.
Note:Floating-point functions use point symbol (".") as decimal mark, ignoring locale settings.
Decimal numbers conversion
C Unsigned integer types size_t Numbers_DecToNum_uint8 (uint8_t *number, const char8_t string[]); size_t Numbers_DecToNum_uint16 (uint16_t *number, const char8_t string[]); size_t Numbers_DecToNum_uint32 (uint32_t *number, const char8_t string[]); size_t Numbers_DecToNum_uint64 (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers_DecToNum_sint8 (sint8_t *number, const char8_t string[]); size_t Numbers_DecToNum_sint16 (sint16_t *number, const char8_t string[]); size_t Numbers_DecToNum_sint32 (sint32_t *number, const char8_t string[]); size_t Numbers_DecToNum_sint64 (sint64_t *number, const char8_t string[]); Floating-point types size_t Numbers_DecToNum_flt32 (flt32_t *number, const char8_t string[]); size_t Numbers_DecToNum_flt64 (flt64_t *number, const char8_t string[]); Other types size_t Numbers_DecToNum_size (size_t *number, const char8_t string[]);
C++ Unsigned integer types size_t Numbers::DecToNum (uint8_t *number, const char8_t string[]); size_t Numbers::DecToNum (uint16_t *number, const char8_t string[]); size_t Numbers::DecToNum (uint32_t *number, const char8_t string[]); size_t Numbers::DecToNum (uint64_t *number, const char8_t string[]); Signed integer types size_t Numbers::DecToNum (sint8_t *number, const char8_t string[]); size_t Numbers::DecToNum (sint16_t *number, const char8_t string[]); size_t Numbers::DecToNum (sint32_t *number, const char8_t string[]); size_t Numbers::DecToNum (sint64_t *number, const char8_t string[]); Floating-point types size_t Numbers::DecToNum (flt32_t *number, const char8_t string[]); size_t Numbers::DecToNum (flt64_t *number, const char8_t string[]); Other types size_t Numbers::DecToNum (size_t *number, const char8_t string[]);
Description: Convert number in decimal format, with possibly preceding "+" or "-" sign, to internal computer format, depending of expected data type.
Parameters:
- number - pointer to a variable where number value should be placed
- string - pointer to string where decimal number may be found
Return value:
- Count of characters (not bytes), including preceding white symbols, which were read and converted.
- -1 if no number is found.
- 0 (zero) if overflow is occurred during integer number conversion, or exponent overflow is occurred dufing floating-point number conversion.
Note:Floating-point functions use point symbol (".") as decimal mark, ignoring locale settings.