1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

AK+LibWeb: Make clamp_to_int generic over all integrals

This commit is contained in:
timmot 2023-11-18 20:00:14 +11:00 committed by Andreas Kling
parent cf7b13c708
commit da3cfd5bbc
Notes: sideshowbarker 2024-07-16 20:44:03 +09:00
2 changed files with 12 additions and 12 deletions

View file

@ -1026,17 +1026,17 @@ constexpr T pow(T x, T y)
return exp2<T>(y * log2<T>(x));
}
template<typename T>
constexpr int clamp_to_int(T value)
template<Integral I, typename T>
constexpr I clamp_to(T value)
{
if (value >= static_cast<T>(NumericLimits<int>::max()))
return NumericLimits<int>::max();
if (value >= static_cast<T>(NumericLimits<I>::max()))
return NumericLimits<I>::max();
if (value <= static_cast<T>(NumericLimits<int>::min()))
return NumericLimits<int>::min();
if (value <= static_cast<T>(NumericLimits<I>::min()))
return NumericLimits<I>::min();
if constexpr (IsFloatingPoint<T>)
return round_to<int>(value);
return round_to<I>(value);
return value;
}