diff --git a/Include/auROXTL/auNumberUtils.hpp b/Include/auROXTL/auNumberUtils.hpp index 48cf90d..3d07a2b 100644 --- a/Include/auROXTL/auNumberUtils.hpp +++ b/Include/auROXTL/auNumberUtils.hpp @@ -42,10 +42,33 @@ constexpr const T AuPageRound(const T value, const T pageSize) // TODO: out of order #include "auBitsUtils.hpp" +template +const bool AuIsPow2(const T value) +{ + return (value) && (value & (value - 1) == 0); +} + +template +const T AuNextPow2(const T value) +{ + if constexpr (AuIsSame_v || + AuIsSame_v) + { + return AuNextPow2(value); + } + else + { + AuUInt8 ret; + AuBitScanReverse(ret, value); + return T(1) << (T(ret) + T(1)); + } +} + template const T AuRoundUpPow2(const T value) { - if constexpr (AuIsSame_v) + if constexpr (AuIsSame_v || + AuIsSame_v) { return AuRoundUpPow2(value); } @@ -53,14 +76,15 @@ const T AuRoundUpPow2(const T value) { AuUInt8 ret; AuBitScanReverse(ret, value); - return T(1) << (ret + T(1)); + return T(1) << (T(ret) + T(T(1) << T(ret) == value ? 0 : 1)); } } template const T AuRoundDownPow2(const T value) { - if constexpr (AuIsSame_v) + if constexpr (AuIsSame_v || + AuIsSame_v) { return AuRoundDownPow2(value); } @@ -68,6 +92,6 @@ const T AuRoundDownPow2(const T value) { AuUInt8 ret; AuBitScanReverse(ret, value); - return T(1) << ret; + return T(1) << T(ret); } } \ No newline at end of file