BAN: make all Math functions inline constexpr

This commit is contained in:
Bananymous 2023-02-22 01:17:56 +02:00
parent 10b6d51522
commit 9aab67fed8
1 changed files with 8 additions and 6 deletions

View File

@ -2,29 +2,31 @@
#include <BAN/Traits.h>
#include <stdint.h>
namespace BAN::Math
{
template<typename T>
T min(T a, T b)
inline constexpr T min(T a, T b)
{
return a < b ? a : b;
}
template<typename T>
T max(T a, T b)
inline constexpr T max(T a, T b)
{
return a > b ? a : b;
}
template<typename T>
T clamp(T x, T min, T max)
inline constexpr T clamp(T x, T min, T max)
{
return x < min ? min : x > max ? max : x;
}
template<integral T>
T gcd(T a, T b)
inline constexpr T gcd(T a, T b)
{
T t;
while (b)
@ -37,13 +39,13 @@ namespace BAN::Math
}
template<integral T>
T lcm(T a, T b)
inline constexpr T lcm(T a, T b)
{
return a / gcd(a, b) * b;
}
template<integral T>
T div_round_up(T a, T b)
inline constexpr T div_round_up(T a, T b)
{
return (a + b - 1) / b;
}