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:
parent
cf7b13c708
commit
da3cfd5bbc
Notes:
sideshowbarker
2024-07-16 20:44:03 +09:00
Author: https://github.com/timmot
Commit: da3cfd5bbc
Pull-request: https://github.com/SerenityOS/serenity/pull/21980
Reviewed-by: https://github.com/MacDue ✅
2 changed files with 12 additions and 12 deletions
14
AK/Math.h
14
AK/Math.h
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue