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
Notes: sideshowbarker 2024-07-17 19:42:16 +09:00
8 changed files with 20 additions and 16 deletions

View file

@ -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)
{

View file

@ -295,12 +295,6 @@ constexpr T log2(T x)
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>
constexpr T log10(T x)
{
@ -353,11 +347,7 @@ constexpr T exp2(T exponent)
: "0"(exponent));
return res;
}
template<Integral T>
constexpr T exp2(T exponent)
{
return 1u << exponent;
}
}
using Exponentials::exp;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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