aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
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