moreinttypes 1.8.0
Minimal library of enhanced integer types for C
Loading...
Searching...
No Matches
Math Lib

Functions for integral math. More...

Macros

#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.
 

Detailed Description

Functions for integral math.

Macro Definition Documentation

◆ 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

#define USE_64_BITS

When defined, exposes 64-bit versions of this library's functions.

Remarks
Must be defined before including moreinttypes/core.h or moreinttypes/utils.h

Function Documentation

◆ 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
bufferA string buffer to use as scratch memory.
nAn integer.
Returns
A formatted string representation of n in base-2 notation.
Remarks
Negative values will be cast to their 2's complement by implicit type conversion.

◆ 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
bufferA string buffer to use as scratch memory.
nAn integer.
Returns
A formatted string representation of n in base-2 notation.
Remarks
Negative values will be cast to their 2's complement by implicit type conversion.

◆ factorial_of()

long double factorial_of ( uint32_t  n)

Returns the factorial of an unsigned integer.

Parameters
nAn unsigned integer.
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
Remarks
Signed arguments will be cast to their unsigned equivalents. Integer overflows are signalled by an error message and a 0 return value.

◆ factorial_of_64()

long double factorial_of_64 ( uint64_t  n)

Returns the factorial of an unsigned integer.

Parameters
nAn unsigned integer.
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
Remarks
Signed arguments will be cast to their unsigned equivalents. Integer overflows are signalled by an error message and a 0 return value.

◆ parse_int()

int32_t parse_int ( const char *  str,
int  base 
)

Returns the integral value represented by the given numeric string.

Parameters
strA string representation of an integral value.
baseThe 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
strA string representation of an integral value.
baseThe 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
strA string representation of an integral value.
valThe 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
strA string representation of an integral value.
baseThe 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
strA string representation of an integral value.
baseThe radix to use when parsing str.
Returns
The integral value of str, otherwise 0.
Remarks
Negative values will be cast to their 2's complement by implicit type conversion.