From 408481c22d42fad901e4bd6fb35aab1b0a4e4e3c Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 14 Dec 2017 01:36:07 +0100 Subject: [PATCH] util-math: Functions to calculate nearest power of two values --- source/util-math.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/util-math.h b/source/util-math.h index c48d98dc..a2e36fb2 100644 --- a/source/util-math.h +++ b/source/util-math.h @@ -31,3 +31,11 @@ inline double_t Gaussian1D(double_t x, double_t o) { double_t a = (1.0 / (o * PI2_SQROOT)); 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))); +}