|
template<typename T, typename R = double> |
constexpr R | mtcore::math::floor_constexpr (T num) noexcept |
| Constexpr floor function.
|
|
template<typename T, typename R = double> |
constexpr R | mtcore::math::ceil_constexpr (T num) noexcept |
| Constexpr ceil function.
|
|
template<typename T, typename R = T> |
constexpr R | mtcore::math::floor (T num) noexcept |
| Floors a number with support for constexpr and fast runtime compilation.
|
|
template<typename T, typename R = T> |
constexpr R | mtcore::math::ceil (T v) noexcept |
| Ceils a number with support for constexpr and fast runtime compilation.
|
|
template<typename L, typename R, typename Res = L> |
constexpr Res | mtcore::math::mod (L left, R right) noexcept |
| Calculates the mathematical mod of two numbers.
|
|
template<typename T> |
constexpr auto | mtcore::math::mod_range (T x, i64 a, i64 b) noexcept -> T |
| x mod [a..b)
|
|
template<typename L, typename R, typename Res = L> |
constexpr auto | mtcore::math::amod (L x, R y) noexcept -> Res |
| x mod [1..y]
|
|
template<typename T, typename R = T> |
constexpr auto | mtcore::math::approx_eq (T x, R y, T epsilon=T{0.000001}) noexcept -> bool |
| Checks if two numbers are approximately equal (within epsilon distance)
|
|
template<typename T> |
constexpr int | mtcore::math::sign (const T &v) |
| Gets the sign (1 for positive, -1 for negative, 0 for zero)
|
|
template<typename L> |
constexpr L | mtcore::math::abs (L l) |
| Gets absolute value of a number.
|
|
template<typename T> |
constexpr T | mtcore::math::int_pow (T val, int exp) |
| Raises to an integer power (positive or negative)
|
|
template<std::integral T> |
constexpr T | mtcore::math::gcd (T a, T b) |
| Calculates the GCD (Greatest Common Divisor) of two integer numbers.
|
|
template<std::integral T> |
constexpr T | mtcore::math::lcm (T a, T b) |
| Calculates the LCM (Least Common Multiple) of two integer numbers.
|
|
template<typename L, typename R, typename Res = L>
Res mtcore::math::mod |
( |
L | left, |
|
|
R | right ) |
|
constexprnoexcept |
Calculates the mathematical mod of two numbers.
Has different negative number handling than %
which allows it to be better for indexes. Also, it's more consistent across platforms and handles floating point numbers as well.
- Template Parameters
-
L | Type of left operand |
R | Type of right operand |
Res | Type of result |
- Parameters
-
left | Left operand |
right | Right operand |
- Returns
- Mod
Definition at line 128 of file core/mtcore/math/core.hpp.
128 {
129 if (std::is_integral_v<L> || std::is_integral_v<R>) {
130 return static_cast<Res
>(
mod(
static_cast<long double>(left),
static_cast<long double>(right)));
131 }
132 else {
133 return static_cast<Res
>(left - right *
math::floor(left / right));
134 }
135 }
constexpr R floor(T num) noexcept
Floors a number with support for constexpr and fast runtime compilation.