From 528d36a13f0412f6a210b2172241f99c430407d1 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Fri, 28 Sep 2018 14:23:26 +0200 Subject: [PATCH] util-math: Fix compile error and add get_power_of_two_* --- source/util-math.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/source/util-math.h b/source/util-math.h index 055ef229..6242c635 100644 --- a/source/util-math.h +++ b/source/util-math.h @@ -84,7 +84,7 @@ namespace util { template inline bool is_power_of_two(T v) { - return T(1ull << uint64_t(log10(T(size)) / log10(2.0))) == v; + return T(1ull << uint64_t(floor(log10(T(v)) / log10(2.0)))) == v; }; template @@ -103,7 +103,7 @@ namespace util { } #pragma push_macro("is_power_of_two_as_loop") -#define is_power_of_two_as_loop(x) \ +#define is_power_of_two_as_loop(x) \ template<> \ inline bool is_power_of_two(x v) \ { \ @@ -118,5 +118,17 @@ namespace util { is_power_of_two_as_loop(int64_t); is_power_of_two_as_loop(uint64_t); #pragma pop_macro("is_power_of_two_as_loop") + + template + inline uint64_t get_power_of_two_floor(T v) + { + return uint64_t(floor(log10(T(v)) / log10(2.0))); + } + + template + inline uint64_t get_power_of_two_ceil(T v) + { + return uint64_t(ceil(log10(T(v)) / log10(2.0))); + } } // namespace math } // namespace util