Miscellaneous math utility functions utilized within the API.
More...
|
#define | INT_SQRT 0 |
|
#define | MAX(a, b) ((a) > (b) ? (a) : (b)) |
| Calculates the maximum of two values.
|
|
#define | MIN(a, b) ((a) < (b) ? (a) : (b)) |
| Calculates the minimum of two values.
|
|
#define | CLAMP(x, min, max) (MIN(MAX((x), (min)), (max))) |
| Clamps a value between a minimum and maximum boundary.
|
|
|
uint32_t | log2i (uint32_t x) |
| Integer Base-2 Logarithm.
|
|
uint32_t | log2_round (uint32_t x) |
| Integer Base-2 Logarithm with rounded result.
|
|
uint32_t | binary_round (uint32_t x) |
| Finding the nearest power-of-two value.
|
|
uint32_t | popcount (uint32_t x) |
| Counting bits set in a 32-bit unsigned integer.
|
|
uint32_t | ispowoftwo (uint32_t x) |
| Determining if an integer is a power of 2.
|
|
uint32_t | absval (int32_t x) |
| Calculates the absolute value.
|
|
uint32_t | floor2 (uint32_t x, uint_fast8_t n) |
| Calculates the floor division by a factor of 2: floor(x / 2^n).
|
|
uint32_t | ceiling2 (uint32_t x, uint_fast8_t n) |
| Calculates the ceildiv division by a factor of 2: ceildiv(x / 2^n).
|
|
uint32_t | ceildiv (uint32_t x, uint32_t y) |
| Calculates the ceildiv division: ceildiv(x / y).
|
|
Miscellaneous math utility functions utilized within the API.
Modules overview:
- Integer Math: Mathematical functionality on integer values.
- Long integer multiplication (32bit x 32bit): double word integer multiplication algorithms.
◆ CLAMP
#define CLAMP |
( |
|
x, |
|
|
|
min, |
|
|
|
max |
|
) |
| (MIN(MAX((x), (min)), (max))) |
Clamps a value between a minimum and maximum boundary.
Clamps the values such that the condition min <= x <= max is true.
- Note
- The condition
min
<= max
must hold!!!
- Parameters
-
x | The input parameter to be clamped. |
min | The minimum or lower boundary. |
max | The maximum or upper boundary. |
- Returns
- The clamped value of the input parameter within [min,max].
◆ INT_SQRT
Enables the integer square root function.
◆ MAX
#define MAX |
( |
|
a, |
|
|
|
b |
|
) |
| ((a) > (b) ? (a) : (b)) |
Calculates the maximum of two values.
- Parameters
-
a | Input parameter. |
b | Input parameter. |
- Returns
- The maximum value of the input parameters.
◆ MIN
#define MIN |
( |
|
a, |
|
|
|
b |
|
) |
| ((a) < (b) ? (a) : (b)) |
Calculates the minimum of two values.
- Parameters
-
a | Input parameter. |
b | Input parameter. |
- Returns
- The minimum value of the input parameters.
◆ absval()
uint32_t absval |
( |
int32_t |
x | ) |
|
|
inline |
Calculates the absolute value.
- Parameters
-
- Returns
- The absolute value of x.
◆ binary_round()
uint32_t binary_round |
( |
uint32_t |
x | ) |
|
|
inline |
Finding the nearest power-of-two value.
Implemented s.t. |x - 2^n| becomes minimum for all n. Special case 0: returns 0; Maximum input: 3037000499; higher number result in overflow! (returns 0)
- Parameters
-
- Returns
- Nearest power-of-two number, i.e. 2^n.
◆ ceildiv()
uint32_t ceildiv |
( |
uint32_t |
x, |
|
|
uint32_t |
y |
|
) |
| |
|
inline |
Calculates the ceildiv division: ceildiv(x / y).
- Parameters
-
- Returns
- The result of the ceildiv division ceildiv(x / y).
◆ ceiling2()
uint32_t ceiling2 |
( |
uint32_t |
x, |
|
|
uint_fast8_t |
n |
|
) |
| |
|
inline |
Calculates the ceildiv division by a factor of 2: ceildiv(x / 2^n).
- Parameters
-
x | Input parameter. |
n | The shift value, maximum is 31. |
- Returns
- The ceildiv division by 2^n result.
◆ floor2()
uint32_t floor2 |
( |
uint32_t |
x, |
|
|
uint_fast8_t |
n |
|
) |
| |
|
inline |
Calculates the floor division by a factor of 2: floor(x / 2^n).
- Parameters
-
x | Input parameter. |
n | The shift value, maximum is 31. |
- Returns
- The floor division by 2^n result.
◆ ispowoftwo()
uint32_t ispowoftwo |
( |
uint32_t |
x | ) |
|
|
inline |
◆ log2_round()
uint32_t log2_round |
( |
uint32_t |
x | ) |
|
|
inline |
Integer Base-2 Logarithm with rounded result.
Calculates the base-2 logarithm for unsigned integer values and returns the rounded result. The result is the integer equivalent of round(log2(x)).
It is finding the nearest power-of-two value s.t. |x - 2^n| becomes minimum for all n.
- Parameters
-
- Returns
- The rounded value of the base-2 logarithm.
◆ log2i()
uint32_t log2i |
( |
uint32_t |
x | ) |
|
|
inline |
Integer Base-2 Logarithm.
Calculates the base-2 logarithm for unsigned integer values. The result is the integer equivalent of floor(log2(x)).
- Parameters
-
- Returns
- The floor of the base-2 logarithm.
◆ popcount()
uint32_t popcount |
( |
uint32_t |
x | ) |
|
|
inline |