diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2023-02-09 15:35:29 +0100 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2023-02-25 20:49:41 -0700 |
commit | 961e26312938fd6fd390c37d70598ca3894bf0a7 (patch) | |
tree | 90dda0a22c42cde5c262391e79030510edbd6ade | |
parent | 7b3b743f888b57e9bb07867e7fe41fd1eb5a737a (diff) | |
download | serenity-961e26312938fd6fd390c37d70598ca3894bf0a7.zip |
AK: Add FixedPoint::clamp
-rw-r--r-- | AK/FixedPoint.h | 9 |
1 files changed, 9 insertions, 0 deletions
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<Underlying>(*this) }; |