diff --git a/AK/Math.h b/AK/Math.h index 4acf9c041d4..6719a4b2523 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -906,6 +906,17 @@ constexpr T round(T x) return ceil(x - .5); } +template +constexpr int clamp_to_int(T value) +{ + if (value >= NumericLimits::max()) { + return NumericLimits::max(); + } else if (value <= NumericLimits::min()) { + return NumericLimits::min(); + } + return value; +} + #undef CONSTEXPR_STATE #undef AARCH64_INSTRUCTION }