From fbb798f98c86c2422de006425dd8f87fda1d5b55 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Sat, 29 Jan 2022 16:51:02 +0100 Subject: [PATCH] AK: Move integral log2 and exp to IntegerMath.h --- AK/IntegralMath.h | 13 +++++++++++++ AK/Math.h | 12 +----------- Kernel/Devices/BlockDevice.h | 2 +- Userland/Applications/Piano/RollWidget.cpp | 2 +- Userland/Games/2048/GameSizeDialog.cpp | 2 +- Userland/Libraries/LibAudio/FlacLoader.cpp | 1 + Userland/Libraries/LibGfx/GIFLoader.cpp | 2 +- Userland/Libraries/LibVideo/MatroskaReader.h | 2 +- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/AK/IntegralMath.h b/AK/IntegralMath.h index 03436832e1e..0a23debb51b 100644 --- a/AK/IntegralMath.h +++ b/AK/IntegralMath.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -13,6 +14,18 @@ namespace AK { +template +constexpr T exp2(T exponent) +{ + return 1u << exponent; +} + +template +constexpr T log2(T x) +{ + return x ? (8 * sizeof(T) - 1) - count_leading_zeroes(static_cast>(x)) : 0; +} + template constexpr I pow(I base, I exponent) { diff --git a/AK/Math.h b/AK/Math.h index 469cc7e5ecb..4912f30e3ca 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -295,12 +295,6 @@ constexpr T log2(T x) return ret; } -template -constexpr T log2(T x) -{ - return x ? (8 * sizeof(T) - 1) - count_leading_zeroes(static_cast>(x)) : 0; -} - template constexpr T log10(T x) { @@ -353,11 +347,7 @@ constexpr T exp2(T exponent) : "0"(exponent)); return res; } -template -constexpr T exp2(T exponent) -{ - return 1u << exponent; -} + } using Exponentials::exp; diff --git a/Kernel/Devices/BlockDevice.h b/Kernel/Devices/BlockDevice.h index ecf544eaa94..5bc75da419f 100644 --- a/Kernel/Devices/BlockDevice.h +++ b/Kernel/Devices/BlockDevice.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include diff --git a/Userland/Applications/Piano/RollWidget.cpp b/Userland/Applications/Piano/RollWidget.cpp index 23dad13867b..8379b4d662f 100644 --- a/Userland/Applications/Piano/RollWidget.cpp +++ b/Userland/Applications/Piano/RollWidget.cpp @@ -8,7 +8,7 @@ #include "RollWidget.h" #include "TrackManager.h" -#include +#include #include #include #include diff --git a/Userland/Games/2048/GameSizeDialog.cpp b/Userland/Games/2048/GameSizeDialog.cpp index 8fda4818524..3f4ccd3a4e5 100644 --- a/Userland/Games/2048/GameSizeDialog.cpp +++ b/Userland/Games/2048/GameSizeDialog.cpp @@ -6,7 +6,7 @@ #include "GameSizeDialog.h" #include "Game.h" -#include +#include #include #include #include diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index c2b0944c56a..68692b55207 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 2dbe15484c7..6860d1ab6b8 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibVideo/MatroskaReader.h b/Userland/Libraries/LibVideo/MatroskaReader.h index 29fc992e689..5995bbdc6ef 100644 --- a/Userland/Libraries/LibVideo/MatroskaReader.h +++ b/Userland/Libraries/LibVideo/MatroskaReader.h @@ -8,7 +8,7 @@ #include "MatroskaDocument.h" #include -#include +#include #include #include #include