From 74f45ae2a723107adce1038a708d2958aca97487 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 22 Jan 2018 09:54:46 -0800 Subject: rfnoc: Factor out ceil_log2() into central location - New file: uhdlib/utils/math.hpp --- host/lib/include/uhdlib/utils/math.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 host/lib/include/uhdlib/utils/math.hpp (limited to 'host/lib/include/uhdlib') diff --git a/host/lib/include/uhdlib/utils/math.hpp b/host/lib/include/uhdlib/utils/math.hpp new file mode 100644 index 000000000..eeb420727 --- /dev/null +++ b/host/lib/include/uhdlib/utils/math.hpp @@ -0,0 +1,25 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0 +// + +// More math, but not meant for public API + +#ifndef INCLUDED_UHDLIB_UTILS_MATH_HPP +#define INCLUDED_UHDLIB_UTILS_MATH_HPP + +#include + +namespace uhd { namespace math { + +/*! log2(num), rounded up to the nearest integer. + */ +template +T ceil_log2(T num){ + return std::ceil(std::log(num)/std::log(T(2))); +} + +}} /* namespace uhd::math */ + +#endif /* INCLUDED_UHDLIB_UTILS_MATH_HPP */ -- cgit v1.2.3