diff options
author | Martin Braun <martin.braun@ettus.com> | 2014-10-23 18:07:07 +0200 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2014-11-20 23:28:37 +0100 |
commit | 27aa985f450a7d2312f8731991d4e4e9ec122e8d (patch) | |
tree | 70c409c1e40d9b067124df18d948c9afd3aa5395 /host/include | |
parent | 55fdf6d4a60cc1f92cee7c27ea3e4c8799aae34e (diff) | |
download | uhd-27aa985f450a7d2312f8731991d4e4e9ec122e8d.tar.gz uhd-27aa985f450a7d2312f8731991d4e4e9ec122e8d.tar.bz2 uhd-27aa985f450a7d2312f8731991d4e4e9ec122e8d.zip |
math: Added a portable log2()
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/utils/math.hpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index 21825c3dc..a41a35d67 100644 --- a/host/include/uhd/utils/math.hpp +++ b/host/include/uhd/utils/math.hpp @@ -18,11 +18,11 @@ #ifndef INCLUDED_UHD_UTILS_MATH_HPP #define INCLUDED_UHD_UTILS_MATH_HPP +#include <cmath> #include <uhd/config.hpp> #include <boost/cstdint.hpp> #include <boost/numeric/conversion/bounds.hpp> - namespace uhd { /*! @@ -237,6 +237,16 @@ namespace fp_compare { == fp_compare::fp_compare_delta<double>(rhs, FREQ_COMPARISON_DELTA_HZ)); } + //! Portable log2() + template <typename float_t> UHD_INLINE + float_t log2(float_t x) + { + // C++11 defines std::log2(), when that's universally supported + // we can switch over. + return std::log(x) / std::log(2); + } + + } // namespace math } // namespace uhd |