util-math: Fix compile error and add get_power_of_two_*

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2018-09-28 14:23:26 +02:00
parent 391fca7497
commit 528d36a13f

View file

@ -84,7 +84,7 @@ namespace util {
template<typename T> template<typename T>
inline bool is_power_of_two(T v) 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<typename T> template<typename T>
@ -118,5 +118,17 @@ namespace util {
is_power_of_two_as_loop(int64_t); is_power_of_two_as_loop(int64_t);
is_power_of_two_as_loop(uint64_t); is_power_of_two_as_loop(uint64_t);
#pragma pop_macro("is_power_of_two_as_loop") #pragma pop_macro("is_power_of_two_as_loop")
template<typename T>
inline uint64_t get_power_of_two_floor(T v)
{
return uint64_t(floor(log10(T(v)) / log10(2.0)));
}
template<typename T>
inline uint64_t get_power_of_two_ceil(T v)
{
return uint64_t(ceil(log10(T(v)) / log10(2.0)));
}
} // namespace math } // namespace math
} // namespace util } // namespace util