AK: Add AK::ceil(float) and AK::ceil_log2(integer)

Co-authored-by: Leon Albrecht <leon2002.la@gmail.com>
This commit is contained in:
MacDue 2022-06-29 18:56:39 +01:00 committed by Andreas Kling
commit 072a78b958
Notes: sideshowbarker 2024-07-17 09:52:05 +09:00
2 changed files with 25 additions and 0 deletions

View file

@ -24,6 +24,17 @@ constexpr T log2(T x)
return x ? (8 * sizeof(T) - 1) - count_leading_zeroes(static_cast<MakeUnsigned<T>>(x)) : 0;
}
template<Integral T>
constexpr T ceil_log2(T x)
{
if (!x)
return 0;
T log = AK::log2(x);
log += (x & ((1 << (log - 1)) - 1)) != 0;
return log;
}
template<Integral I>
constexpr I pow(I base, I exponent)
{