19#ifndef MTCORE_MATH_TEMPLATES_H
20#define MTCORE_MATH_TEMPLATES_H
34 template<
intmax_t A,
intmax_t B>
39 static constexpr auto value = A;
42 template<
intmax_t A,
intmax_t B>
44 static constexpr auto t = B;
46 static constexpr auto a =
t;
56 template<
intmax_t A,
intmax_t B>
69 template<
typename T1,
typename T2>
72 template<
intmax_t N1,
intmax_t D1,
intmax_t N2,
intmax_t D2>
73 struct MultRatios<std::ratio<N1, D1>, std::ratio<N2, D2>> {
74 static constexpr auto NRaw = N1 * N2;
75 static constexpr auto DRaw = D1 * D2;
80 using T = std::ratio<N, D>;
83 static_assert(std::same_as<MultRatios<std::ratio<2, 3>, std::ratio<2, 3>>::T, std::ratio<4, 9>>);
93 template<
typename T1,
typename T2>
96 template<
intmax_t N1,
intmax_t D1,
intmax_t N2,
intmax_t D2>
97 struct AddRatios<std::ratio<N1, D1>, std::ratio<N2, D2>> {
101 static constexpr auto NN1 = N1 *
M1;
102 static constexpr auto NN2 = N2 *
M2;
109 static_assert(std::same_as<AddRatios<std::ratio<2, 15>, std::ratio<1, 5>>::T, std::ratio<1, 3>>);
119 template<
intmax_t Num,
intmax_t Den>
136 template<
intmax_t Num,
intmax_t Den>
138 using T = std::ratio<Den, Num>;
149 template<
intmax_t Num,
intmax_t Den>
151 using T = std::ratio<-Num, Den>;
159 template<
typename T,
int Pow,
bool Odd,
bool Neg,
bool Z>
162 template<
intmax_t N,
intmax_t D>
164 using T = std::ratio<1>;
167 template<
intmax_t N,
intmax_t D,
int Pow,
bool Odd>
172 template<
intmax_t N,
intmax_t D,
int Pow>
174 using R = std::ratio<N, D>;
175 static constexpr auto PN = Pow / 2;
179 template<
intmax_t N,
intmax_t D,
int Pow>
181 using R = std::ratio<N, D>;
186 template<
typename R,
int Pow>
188 using T =
typename IntPowRatioImpl < R, Pow, Pow % 2 == 1, Pow<0, Pow == 0>::T;
constexpr Res mod(L left, R right) noexcept
Calculates the mathematical mod of two numbers.
constexpr T lcm(T a, T b)
Calculates the LCM (Least Common Multiple) of two integer numbers.
constexpr L abs(L l)
Gets absolute value of a number.
constexpr T gcd(T a, T b)
Calculates the GCD (Greatest Common Divisor) of two integer numbers.
Math utilities, often with constexpr support.
static constexpr auto NN2
std::ratio< NN/NG, NewDenom/NG > T
static constexpr auto NN1
static constexpr auto NewDenom
Template to add two std::ratio numbers.
static constexpr auto value
Template to get GCD of numbers.
static constexpr auto value
typename IntPowRatioImpl< std::ratio< D, N >, -Pow,(-Pow) % 2==1, false, false >::T T
typename IntPowRatioImpl< typename MultRatios< R, R >::T, PN, PN % 2==1, false, PN==0 >::T T
typename meta::If< Pow==1, R, typename MultRatios< R, typename IntPowRatioImpl< R, Pow - 1, false, false, Pow - 1==0 >::T >::T >::T T
Template to get the integer power (positive or negative) of a ratio.
typename IntPowRatioImpl< R, Pow, Pow % 2==1, Pow< 0, Pow==0 >::T T
Template to invert a ratio number.
Template to get LCM of numbers.
static constexpr auto value
static constexpr auto Gcd
static constexpr auto NRaw
static constexpr auto DRaw
Template to multiply two std::ratio numbers.
Template to negate the power of a ratio.
static constexpr intmax_t Numerator
static constexpr intmax_t Denominator
Template to get the Numerator and Denominator of a std::ratio.