util-math: Functions to calculate nearest power of two values

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2017-12-14 01:36:07 +01:00
parent d78d3024cc
commit 408481c22d

View file

@ -31,3 +31,11 @@ inline double_t Gaussian1D(double_t x, double_t o) {
double_t a = (1.0 / (o * PI2_SQROOT)); double_t a = (1.0 / (o * PI2_SQROOT));
return a * b; return a * b;
} }
inline size_t GetNearestPowerOfTwoAbove(size_t v) {
return 1 << size_t(ceil(log10(v) / log10(2)));
}
inline size_t GetNearestPowerOfTwoBelow(size_t v) {
return 1 << size_t(floor(log10(v) / log10(2)));
}