From 5ee6b828debbd60e03aff805bfd80e2030715a6f Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 31 Aug 2021 11:49:51 +0200 Subject: uhd: math: Replace wrap-frequency math with a single function In multiple places in the UHD code, we were doing the same calculation for a wrapped frequency (wrap it into the first Nyquist zone). This math was using boost::math, too. Instead of editing every instance, we create a new function, uhd::math::wrap_frequency(), and replace all of its separate implementations with this function. The new function also no longer relies on boost::math::sign. --- host/tests/math_test.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'host/tests') diff --git a/host/tests/math_test.cpp b/host/tests/math_test.cpp index 1fb01f5c1..12ede7f06 100644 --- a/host/tests/math_test.cpp +++ b/host/tests/math_test.cpp @@ -24,3 +24,11 @@ BOOST_AUTO_TEST_CASE(test_sign) BOOST_CHECK_EQUAL(uhd::math::sign(-2.3), -1); BOOST_CHECK_EQUAL(uhd::math::sign(0.0), 0); } + +BOOST_AUTO_TEST_CASE(test_wrap_frequency) +{ + BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(10e6, 200e6), 10e6); + BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(250e6, 200e6), 50e6); + BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(120e6, 200e6), -80e6); + BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(-250e6, 200e6), -50e6); +} -- cgit v1.2.3