diff --git a/libs/math/include/psemek/math/math.hpp b/libs/math/include/psemek/math/math.hpp index 6f3f194a..a84b7871 100644 --- a/libs/math/include/psemek/math/math.hpp +++ b/libs/math/include/psemek/math/math.hpp @@ -183,6 +183,14 @@ namespace psemek::math return (x >= 0) ? std::fmod(x, m) : (m - std::fmod(-x, m)); } + template + auto clamp(T const & x, T const & low, T const & high) + { + using std::min; + using std::max; + return min(high, max(low, x)); + } + template bool make_min(T & target, T const & source) {