Mathmatic calculations and conversions.
◆ M_MIN
#define M_MIN |
( |
|
a, |
|
|
|
b |
|
) |
| ((a)<(b)?(a):(b)) |
◆ M_MAX
#define M_MAX |
( |
|
a, |
|
|
|
b |
|
) |
| ((a)>(b)?(a):(b)) |
◆ M_ABS
#define M_ABS |
( |
|
a | ) |
((a)<0?((a)*-1):(a)) |
◆ M_CLAMP
◆ M_uint64_exp()
M_uint64 M_uint64_exp |
( |
M_uint64 |
num, |
|
|
int |
exponent |
|
) |
| |
Calculate the exponent of an integer x^y (num^exp).
- Parameters
-
[in] | num | Base number. |
[in] | exponent | Exponent. |
- Returns
- num ^ exp
◆ M_uint64_prec_round()
M_uint64 M_uint64_prec_round |
( |
M_uint64 |
num, |
|
|
int |
currentDecimals, |
|
|
int |
wantedDecimals |
|
) |
| |
Round an integer with implied decimals.
- Parameters
-
[in] | num | Number to round. |
[in] | currentDecimals | Current number of implied decimal places. |
[in] | wantedDecimals | Desired number of decimal places in output. Must be <= currentDecimals. |
- Returns
- num rounded to wantedDecimals (output will have wantedDecimals implied decimals).
◆ M_uint64_round_up_to_nearest_multiple()
M_uint64 M_uint64_round_up_to_nearest_multiple |
( |
M_uint64 |
n, |
|
|
M_uint64 |
mul |
|
) |
| |
Round an integer value up to a given multiple.
- Parameters
-
[in] | n | integer value from which to determine the next multiple. |
[in] | mul | integer multiple to use. |
- Returns
- the next value greater than or equal to n that is evenly divisible by mul.
◆ M_uint32_is_power_of_two()
M_bool M_uint32_is_power_of_two |
( |
M_uint32 |
n | ) |
|
Determine if 32bit integer is a power of two.
- Parameters
-
- Returns
- M_TRUE if power of 2, M_FALSE otherwise
◆ M_uint64_is_power_of_two()
M_bool M_uint64_is_power_of_two |
( |
M_uint64 |
n | ) |
|
Determine if 64bit integer is a power of two.
- Parameters
-
- Returns
- M_TRUE if power of 2, M_FALSE otherwise
◆ M_size_t_is_power_of_two()
M_bool M_size_t_is_power_of_two |
( |
size_t |
n | ) |
|
Determine if size_t is a power of two.
- Parameters
-
- Returns
- M_TRUE if power of 2, M_FALSE otherwise
◆ M_uint32_round_up_to_power_of_two()
M_uint32 M_uint32_round_up_to_power_of_two |
( |
M_uint32 |
n | ) |
|
Round a 32bit integer value up to the next power of two.
- Parameters
-
[in] | n | integer value from which to determine the next power of two. |
- Returns
- the next value greater than or equal to n that is a power of two.
◆ M_uint64_round_up_to_power_of_two()
M_uint64 M_uint64_round_up_to_power_of_two |
( |
M_uint64 |
n | ) |
|
Round a 64bit integer value up to the next power of two.
- Parameters
-
[in] | n | integer value from which to determine the next power of two. |
- Returns
- the next value greater than or equal to n that is a power of two.
◆ M_size_t_round_up_to_power_of_two()
size_t M_size_t_round_up_to_power_of_two |
( |
size_t |
n | ) |
|
Round a size_t value up to the next power of two.
- Parameters
-
[in] | n | integer value from which to determine the next power of two. |
- Returns
- the next value greater than or equal to n that is a power of two.
◆ M_uint32_round_down_to_power_of_two()
M_uint32 M_uint32_round_down_to_power_of_two |
( |
M_uint32 |
n | ) |
|
Round a 32bit integer value down to the last power of two.
- Parameters
-
[in] | n | integer value from which to determine the next power of two. |
- Returns
- the next value greater than or equal to n that is a power of two.
◆ M_uint64_round_down_to_power_of_two()
M_uint64 M_uint64_round_down_to_power_of_two |
( |
M_uint64 |
n | ) |
|
Round a 64bit integer value down to the last power of two.
- Parameters
-
[in] | n | integer value from which to determine the next power of two. |
- Returns
- the next value greater than or equal to n that is a power of two.
◆ M_size_t_round_down_to_power_of_two()
size_t M_size_t_round_down_to_power_of_two |
( |
size_t |
n | ) |
|
Round a size_t value down to the last power of two.
- Parameters
-
[in] | n | integer value from which to determine the next power of two. |
- Returns
- the next value greater than or equal to n that is a power of two.
◆ M_uint32_log2()
M_uint8 M_uint32_log2 |
( |
M_uint32 |
n | ) |
|
Get the log2 of a 32bit integer. n is rounded down if not power of 2, can use M_uint32_round_up_to_power_of_two() to round n up first.
- Parameters
-
[in] | n | integer value to get the log2 for |
- Returns
- log2 of n
◆ M_uint64_log2()
M_uint8 M_uint64_log2 |
( |
M_uint64 |
n | ) |
|
Get the log2 of a 64bit integer. n is rounded down if not power of 2, can use M_uint64_round_up_to_power_of_two() to round n up first.
- Parameters
-
[in] | n | integer value to get the log2 for |
- Returns
- log2 of n
◆ M_sign_extend()
M_int64 M_sign_extend |
( |
M_uint64 |
x, |
|
|
size_t |
num_bits |
|
) |
| |
Increase the number of bits while keeping the sign.
- Parameters
-
[in] | x | Value to sign extend |
[in] | num_bits | The number of bits to extend from |
- Returns
- sign extended value
◆ M_uint64_count_digits()
int M_uint64_count_digits |
( |
M_uint64 |
num | ) |
|
Count number of decimal digits in an integer.
- Parameters
-
[in] | num | Number to count digits. |
- Returns
- number of digits in integer.
◆ M_uint8_popcount()
M_uint8 M_uint8_popcount |
( |
M_uint8 |
x | ) |
|
Count number of set bits in a single byte.
- Parameters
-
[in] | x | value to count bits in |
- Returns
- number of set (1) bits in x
◆ M_uint64_popcount()
M_uint8 M_uint64_popcount |
( |
M_uint64 |
num | ) |
|
Count number of set bits in a 64bit integer.
- Parameters
-
[in] | num | value to count bits in |
- Returns
- number of set (1) bits in num
◆ M_math_modf()
double M_math_modf |
( |
double |
x, |
|
|
double * |
iptr |
|
) |
| |
Floating point modulus.
Splits floating point number into integer and fractional parts.
- Parameters
-
[in] | x | Number to split. |
[out] | iptr | Integer part of number. |
- Returns
- Fractional part of number.
◆ M_math_round()
double M_math_round |
( |
double |
x | ) |
|
Floating point rounding.
- Parameters
-
- Returns
- Number rounded.