mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add clamp_to_int(value) in Math.h
clamp_to_int clamps value to valid range of int values so resulting value does not overflow. It is going to be used to clamp float or double values to int that represents fixed-point value of CSSPixels.
This commit is contained in:
parent
c66dbc99ee
commit
d216621d2a
Notes:
sideshowbarker
2024-07-17 09:48:50 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/d216621d2a Pull-request: https://github.com/SerenityOS/serenity/pull/20153 Reviewed-by: https://github.com/MacDue Reviewed-by: https://github.com/axgallo
1 changed files with 11 additions and 0 deletions
11
AK/Math.h
11
AK/Math.h
|
@ -906,6 +906,17 @@ constexpr T round(T x)
|
||||||
return ceil(x - .5);
|
return ceil(x - .5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr int clamp_to_int(T value)
|
||||||
|
{
|
||||||
|
if (value >= NumericLimits<int>::max()) {
|
||||||
|
return NumericLimits<int>::max();
|
||||||
|
} else if (value <= NumericLimits<int>::min()) {
|
||||||
|
return NumericLimits<int>::min();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
#undef CONSTEXPR_STATE
|
#undef CONSTEXPR_STATE
|
||||||
#undef AARCH64_INSTRUCTION
|
#undef AARCH64_INSTRUCTION
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue