diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-01-22 09:54:46 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-02-19 14:51:47 -0800 |
commit | 74f45ae2a723107adce1038a708d2958aca97487 (patch) | |
tree | a87139dfef5c863a71f3e4e832c2de3e914b5831 /host/lib/include/uhdlib | |
parent | eff796f64b1e05036b7eca2185f53528a0de870b (diff) | |
download | uhd-74f45ae2a723107adce1038a708d2958aca97487.tar.gz uhd-74f45ae2a723107adce1038a708d2958aca97487.tar.bz2 uhd-74f45ae2a723107adce1038a708d2958aca97487.zip |
rfnoc: Factor out ceil_log2() into central location
- New file: uhdlib/utils/math.hpp
Diffstat (limited to 'host/lib/include/uhdlib')
-rw-r--r-- | host/lib/include/uhdlib/utils/math.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
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 <cmath> + +namespace uhd { namespace math { + +/*! log2(num), rounded up to the nearest integer. + */ +template <class T> +T ceil_log2(T num){ + return std::ceil(std::log(num)/std::log(T(2))); +} + +}} /* namespace uhd::math */ + +#endif /* INCLUDED_UHDLIB_UTILS_MATH_HPP */ |