From b52852537aa4d4ae2523b5992c9288de86a12899 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sun, 29 Jun 2025 13:08:36 -0500 Subject: [PATCH] math: add clamp --- math/math.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; +}