Functions for integral math.
More...
|
#define | USE_64_BITS |
| When defined, exposes 64-bit versions of this library's functions.
|
|
long double | factorial_of (uint32_t n) |
| Returns the factorial of an unsigned integer.
|
|
long double | factorial_of_64 (uint64_t n) |
| Returns the factorial of an unsigned integer.
|
|
int32_t | parse_int (const char *str, int base) |
| Returns the integral value represented by the given numeric string.
|
|
uint32_t | parse_uint (const char *str, int base) |
| Returns the integral value represented by the given numeric string.
|
|
int64_t | parse_int_64 (const char *str, int base) |
| Returns the integral value represented by the given numeric string.
|
|
uint64_t | parse_uint_64 (const char *str, int base) |
| Returns the integral value represented by the given numeric string.
|
|
bool | parse_succeeded (const char *str, const int64_t val) |
| Returns true if and only if the given string represents the given value.
|
|
const char * | binary_string (char *buffer, uint32_t n) |
| Converts an integer to a string representation of its binary equivalent, formatted in space-separated nibbles.
|
|
const char * | binary_string_64 (char *buffer, uint64_t n) |
| Converts an integer to a string representation of its binary equivalent, formatted in space-separated nibbles.
|
|
#define | MATCH_ARCH(func_name) |
| Returns the appropriate function name based on the expected integer type.
|
|
Functions for integral math.
◆ MATCH_ARCH
#define MATCH_ARCH |
( |
|
func_name | ) |
|
Returns the appropriate function name based on the expected integer type.
Names will be appended with "_64" if USE_64_BITS has been set.
◆ USE_64_BITS
When defined, exposes 64-bit versions of this library's functions.
◆ binary_string()
const char * binary_string |
( |
char * |
buffer, |
|
|
uint32_t |
n |
|
) |
| |
Converts an integer to a string representation of its binary equivalent, formatted in space-separated nibbles.
- Parameters
-
buffer | A string buffer to use as scratch memory. |
n | An integer. |
- Returns
- A formatted string representation of
n
in base-2 notation.
◆ binary_string_64()
const char * binary_string_64 |
( |
char * |
buffer, |
|
|
uint64_t |
n |
|
) |
| |
Converts an integer to a string representation of its binary equivalent, formatted in space-separated nibbles.
- Parameters
-
buffer | A string buffer to use as scratch memory. |
n | An integer. |
- Returns
- A formatted string representation of
n
in base-2 notation.
◆ factorial_of()
long double factorial_of |
( |
uint32_t |
n | ) |
|
Returns the factorial of an unsigned integer.
- Parameters
-
- Returns
- The factorial of
n
, if computable, otherwise 0
.
The range of representable return values will depend on the bit width of the host system's long double
type. A rough estimate:
Size (bytes) | Computable input values |
32-bit |
8 | <= 170 |
12 | <= 1754 |
64-bit |
16 | <= 1754 |
◆ factorial_of_64()
long double factorial_of_64 |
( |
uint64_t |
n | ) |
|
Returns the factorial of an unsigned integer.
- Parameters
-
- Returns
- The factorial of
n
, if computable, otherwise 0
.
The range of representable return values will depend on the bit width of the host system's long double
type. A rough estimate:
Size (bytes) | Computable input values |
32-bit |
8 | <= 170 |
12 | <= 1754 |
64-bit |
16 | <= 1754 |
◆ parse_int()
int32_t parse_int |
( |
const char * |
str, |
|
|
int |
base |
|
) |
| |
Returns the integral value represented by the given numeric string.
- Parameters
-
str | A string representation of an integral value. |
base | The radix to use when parsing str . |
- Returns
- The integral value of
str
, otherwise 0
.
◆ parse_int_64()
int64_t parse_int_64 |
( |
const char * |
str, |
|
|
int |
base |
|
) |
| |
Returns the integral value represented by the given numeric string.
- Parameters
-
str | A string representation of an integral value. |
base | The radix to use when parsing str . |
- Returns
- The integral value of
str
, otherwise 0
.
◆ parse_succeeded()
bool parse_succeeded |
( |
const char * |
str, |
|
|
const int64_t |
val |
|
) |
| |
Returns true if and only if the given string represents the given value.
- Parameters
-
str | A string representation of an integral value. |
val | The value returned after parsing str . |
- Returns
- True if
val
really is the value represented by str
.
◆ parse_uint()
uint32_t parse_uint |
( |
const char * |
str, |
|
|
int |
base |
|
) |
| |
Returns the integral value represented by the given numeric string.
- Parameters
-
str | A string representation of an integral value. |
base | The radix to use when parsing str . |
- Returns
- The integral value of
str
, otherwise 0
.
◆ parse_uint_64()
uint64_t parse_uint_64 |
( |
const char * |
str, |
|
|
int |
base |
|
) |
| |
Returns the integral value represented by the given numeric string.
- Parameters
-
str | A string representation of an integral value. |
base | The radix to use when parsing str . |
- Returns
- The integral value of
str
, otherwise 0
.