From 961e26312938fd6fd390c37d70598ca3894bf0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 9 Feb 2023 15:35:29 +0100 Subject: [PATCH] AK: Add FixedPoint::clamp --- AK/FixedPoint.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AK/FixedPoint.h b/AK/FixedPoint.h index d4513efa19..9b4c717ec0 100644 --- a/AK/FixedPoint.h +++ b/AK/FixedPoint.h @@ -95,6 +95,15 @@ public: return create_raw(m_value & radix_mask); } + constexpr This clamp(This minimum, This maximum) const + { + if (*this < minimum) + return minimum; + if (*this > maximum) + return maximum; + return *this; + } + constexpr This round() const { return This { static_cast(*this) };