1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

AK: Move integral log2 and exp to IntegerMath.h

This commit is contained in:
Hendiadyoin1 2022-01-29 16:51:02 +01:00 committed by Brian Gianforcaro
parent f6ddaef8bf
commit fbb798f98c
8 changed files with 20 additions and 16 deletions

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/BuiltinWrappers.h>
#include <AK/Concepts.h> #include <AK/Concepts.h>
#include <AK/Types.h> #include <AK/Types.h>
@ -13,6 +14,18 @@
namespace AK { 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> template<Integral I>
constexpr I pow(I base, I exponent) constexpr I pow(I base, I exponent)
{ {

View file

@ -295,12 +295,6 @@ constexpr T log2(T x)
return ret; return ret;
} }
template<Integral T>
constexpr T log2(T x)
{
return x ? (8 * sizeof(T) - 1) - count_leading_zeroes(static_cast<MakeUnsigned<T>>(x)) : 0;
}
template<FloatingPoint T> template<FloatingPoint T>
constexpr T log10(T x) constexpr T log10(T x)
{ {
@ -353,11 +347,7 @@ constexpr T exp2(T exponent)
: "0"(exponent)); : "0"(exponent));
return res; return res;
} }
template<Integral T>
constexpr T exp2(T exponent)
{
return 1u << exponent;
}
} }
using Exponentials::exp; using Exponentials::exp;

View file

@ -6,7 +6,7 @@
#pragma once #pragma once
#include <AK/Math.h> #include <AK/IntegralMath.h>
#include <AK/Weakable.h> #include <AK/Weakable.h>
#include <Kernel/Devices/Device.h> #include <Kernel/Devices/Device.h>

View file

@ -8,7 +8,7 @@
#include "RollWidget.h" #include "RollWidget.h"
#include "TrackManager.h" #include "TrackManager.h"
#include <AK/Math.h> #include <AK/IntegralMath.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/Scrollbar.h> #include <LibGUI/Scrollbar.h>
#include <LibGfx/Font.h> #include <LibGfx/Font.h>

View file

@ -6,7 +6,7 @@
#include "GameSizeDialog.h" #include "GameSizeDialog.h"
#include "Game.h" #include "Game.h"
#include <AK/Math.h> #include <AK/IntegralMath.h>
#include <LibGUI/BoxLayout.h> #include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h> #include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h> #include <LibGUI/CheckBox.h>

View file

@ -8,6 +8,7 @@
#include <AK/FixedArray.h> #include <AK/FixedArray.h>
#include <AK/FlyString.h> #include <AK/FlyString.h>
#include <AK/Format.h> #include <AK/Format.h>
#include <AK/IntegralMath.h>
#include <AK/Math.h> #include <AK/Math.h>
#include <AK/ScopeGuard.h> #include <AK/ScopeGuard.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>

View file

@ -6,7 +6,7 @@
#include <AK/Array.h> #include <AK/Array.h>
#include <AK/Debug.h> #include <AK/Debug.h>
#include <AK/Math.h> #include <AK/IntegralMath.h>
#include <AK/Memory.h> #include <AK/Memory.h>
#include <AK/MemoryStream.h> #include <AK/MemoryStream.h>
#include <AK/NonnullOwnPtrVector.h> #include <AK/NonnullOwnPtrVector.h>

View file

@ -8,7 +8,7 @@
#include "MatroskaDocument.h" #include "MatroskaDocument.h"
#include <AK/Debug.h> #include <AK/Debug.h>
#include <AK/Math.h> #include <AK/IntegralMath.h>
#include <AK/NonnullOwnPtrVector.h> #include <AK/NonnullOwnPtrVector.h>
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>