aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-01-15 15:04:03 -0800
committerBrent Stapleton <brent.stapleton@ettus.com>2019-01-18 09:37:12 -0800
commit7fab6b807ef5b86c97577170b7b5fdc667e3fa20 (patch)
tree0cdb0ab0711599d36f192c77a6129abbf235ad73 /host/include
parent11c7e561fc29b56ade8ae6ec549b21c533540e8a (diff)
downloaduhd-7fab6b807ef5b86c97577170b7b5fdc667e3fa20.tar.gz
uhd-7fab6b807ef5b86c97577170b7b5fdc667e3fa20.tar.bz2
uhd-7fab6b807ef5b86c97577170b7b5fdc667e3fa20.zip
math: Replace boost::*::{lcm,gcd}() with portable versions
Boost changed the lcm() and gcd() functions in Boost 1.67. This creates portable UHD versions to be used instead. They use various Boost versions under the hood conditionally.
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/utils/math.hpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp
index 8606923fa..944e9a951 100644
--- a/host/include/uhd/utils/math.hpp
+++ b/host/include/uhd/utils/math.hpp
@@ -12,6 +12,15 @@
#include <stdint.h>
#include <boost/numeric/conversion/bounds.hpp>
#include <cmath>
+#if BOOST_VERSION >= 106700
+# include <boost/integer/common_factor.hpp>
+// "bmint" for "boost math integer"
+namespace _bmint = boost::integer;
+#else
+# include <boost/math/common_factor.hpp>
+namespace _bmint = boost::math;
+#endif
+
namespace uhd {
@@ -223,6 +232,20 @@ UHD_INLINE bool frequencies_are_equal(double lhs, double rhs)
== fp_compare::fp_compare_delta<double>(rhs, FREQ_COMPARISON_DELTA_HZ));
}
+//! Portable version of lcm() across Boost versions
+template <typename IntegerType> inline IntegerType lcm(IntegerType x, IntegerType y)
+{
+ // Note: _bmint is defined conditionally at the top of the file
+ return _bmint::lcm<IntegerType>(x, y);
+}
+
+//! Portable version of gcd() across Boost versions
+template <typename IntegerType> inline IntegerType gcd(IntegerType x, IntegerType y)
+{
+ // Note: _bmint is defined conditionally at the top of the file
+ return _bmint::gcd<IntegerType>(x, y);
+}
+
} // namespace math
} // namespace uhd