2022-12-30 19:52:16 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-02-19 00:48:56 +02:00
|
|
|
#include <BAN/Traits.h>
|
|
|
|
|
2023-02-22 01:17:56 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-01-10 19:11:27 +02:00
|
|
|
namespace BAN::Math
|
2022-12-30 19:52:16 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
template<typename T>
|
2023-02-22 01:17:56 +02:00
|
|
|
inline constexpr T min(T a, T b)
|
2022-12-30 19:52:16 +02:00
|
|
|
{
|
|
|
|
return a < b ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2023-02-22 01:17:56 +02:00
|
|
|
inline constexpr T max(T a, T b)
|
2022-12-30 19:52:16 +02:00
|
|
|
{
|
|
|
|
return a > b ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2023-02-22 01:17:56 +02:00
|
|
|
inline constexpr T clamp(T x, T min, T max)
|
2022-12-30 19:52:16 +02:00
|
|
|
{
|
|
|
|
return x < min ? min : x > max ? max : x;
|
|
|
|
}
|
|
|
|
|
2023-02-19 00:48:56 +02:00
|
|
|
template<integral T>
|
2023-02-22 01:17:56 +02:00
|
|
|
inline constexpr T gcd(T a, T b)
|
2023-01-10 19:11:27 +02:00
|
|
|
{
|
|
|
|
T t;
|
|
|
|
while (b)
|
|
|
|
{
|
|
|
|
t = b;
|
|
|
|
b = a % b;
|
|
|
|
a = t;
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2023-02-19 00:48:56 +02:00
|
|
|
template<integral T>
|
2023-02-22 01:17:56 +02:00
|
|
|
inline constexpr T lcm(T a, T b)
|
2023-01-10 19:11:27 +02:00
|
|
|
{
|
|
|
|
return a / gcd(a, b) * b;
|
|
|
|
}
|
|
|
|
|
2023-02-19 00:48:56 +02:00
|
|
|
template<integral T>
|
2023-02-22 01:17:56 +02:00
|
|
|
inline constexpr T div_round_up(T a, T b)
|
2023-02-19 00:48:56 +02:00
|
|
|
{
|
|
|
|
return (a + b - 1) / b;
|
|
|
|
}
|
|
|
|
|
2022-12-30 19:52:16 +02:00
|
|
|
}
|