diff --git a/math/math.hpp b/math/math.hpp index 4a79a8c..e4bd95b 100644 --- a/math/math.hpp +++ b/math/math.hpp @@ -49,3 +49,13 @@ inline constexpr T min(const T a, const T b) noexcept { return (a < b) ? a : b; } + +template +inline constexpr T clamp(const T n, const T l, const T h) noexcept +{ + if (n < l) + return l; + if (n > h) + return h; + return n; +}