From cfdb3ede9819184ad728f3ad6a155d5f5f6f1dd7 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 3 Feb 2022 00:22:37 -0600 Subject: [PATCH] [ox/std] Add ox::clamp (synced from 78942ce21d75889279e1ebd13804225e098310ca) --- src/ox/std/math.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ox/std/math.hpp b/src/ox/std/math.hpp index 57a8ea7f9..28f77ec7c 100644 --- a/src/ox/std/math.hpp +++ b/src/ox/std/math.hpp @@ -24,6 +24,12 @@ constexpr const T &max(const T &a, const T &b) noexcept { return a > b ? a : b; } +template +[[nodiscard]] +constexpr const T &clamp(const T &v, const T &lo, const T &hi) noexcept { + return min(ox::max(v, lo), hi); +} + template [[nodiscard]] constexpr I pow(I v, int e) noexcept {