mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +00:00
AK: Move integral log2 and exp to IntegerMath.h
This commit is contained in:
parent
f6ddaef8bf
commit
fbb798f98c
8 changed files with 20 additions and 16 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/BuiltinWrappers.h>
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
|
@ -13,6 +14,18 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<Integral T>
|
||||
constexpr T exp2(T exponent)
|
||||
{
|
||||
return 1u << exponent;
|
||||
}
|
||||
|
||||
template<Integral T>
|
||||
constexpr T log2(T x)
|
||||
{
|
||||
return x ? (8 * sizeof(T) - 1) - count_leading_zeroes(static_cast<MakeUnsigned<T>>(x)) : 0;
|
||||
}
|
||||
|
||||
template<Integral I>
|
||||
constexpr I pow(I base, I exponent)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue