diff options
-rw-r--r-- | host/include/uhd/rfnoc/siggen_block_control.hpp | 7 | ||||
-rw-r--r-- | host/include/uhd/utils/math.hpp | 2 | ||||
-rw-r--r-- | host/lib/rfnoc/siggen_block_control.cpp | 7 | ||||
-rw-r--r-- | host/tests/rfnoc_block_tests/siggen_block_test.cpp | 12 |
4 files changed, 13 insertions, 15 deletions
diff --git a/host/include/uhd/rfnoc/siggen_block_control.hpp b/host/include/uhd/rfnoc/siggen_block_control.hpp index 944ecc4e0..e599659b6 100644 --- a/host/include/uhd/rfnoc/siggen_block_control.hpp +++ b/host/include/uhd/rfnoc/siggen_block_control.hpp @@ -6,10 +6,9 @@ #pragma once -#define _USE_MATH_DEFINES #include <uhd/config.hpp> #include <uhd/rfnoc/noc_block_base.hpp> -#include <cmath> +#include <uhd/utils/math.hpp> #include <complex> namespace uhd { namespace rfnoc { @@ -195,8 +194,8 @@ public: if (sample_rate <= 0.0) { throw uhd::value_error("sample_rate must be > 0.0"); } - const double phase_inc = (frequency / sample_rate) * 2.0 * M_PI; - if (phase_inc < -M_PI || phase_inc > M_PI) { + const double phase_inc = (frequency / sample_rate) * 2.0 * uhd::math::PI; + if (phase_inc < -uhd::math::PI || phase_inc > uhd::math::PI) { throw uhd::value_error("frequency must be in [-samp_rate/2, samp_rate/2]"); } set_sine_phase_increment(phase_inc, port); diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index d442d6a94..becc256f1 100644 --- a/host/include/uhd/utils/math.hpp +++ b/host/include/uhd/utils/math.hpp @@ -30,6 +30,8 @@ namespace uhd { */ namespace math { +static const double PI = 3.14159265358979323846; + /*! * Define epsilon values for floating point comparisons. * diff --git a/host/lib/rfnoc/siggen_block_control.cpp b/host/lib/rfnoc/siggen_block_control.cpp index fe963a1c3..fa527f3f6 100644 --- a/host/lib/rfnoc/siggen_block_control.cpp +++ b/host/lib/rfnoc/siggen_block_control.cpp @@ -4,7 +4,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#define _USE_MATH_DEFINES #include <uhd/convert.hpp> #include <uhd/exception.hpp> #include <uhd/rfnoc/defaults.hpp> @@ -12,8 +11,8 @@ #include <uhd/rfnoc/property.hpp> #include <uhd/rfnoc/registry.hpp> #include <uhd/rfnoc/siggen_block_control.hpp> +#include <uhd/utils/math.hpp> #include <uhdlib/utils/narrow.hpp> -#include <cmath> #include <limits> #include <string> @@ -182,12 +181,12 @@ private: }); register_property(&_prop_phase_inc.back(), [this, port]() { const double phase_inc = _prop_phase_inc.at(port).get(); - if (phase_inc < (-M_PI) || phase_inc > (M_PI)) { + if (phase_inc < (-uhd::math::PI) || phase_inc > (uhd::math::PI)) { throw uhd::value_error( "Phase increment value must be in [-pi, pi]"); } const int16_t phase_inc_scaled_rads_fp = - clamp<int16_t>((phase_inc / M_PI) * 8192.0); + clamp<int16_t>((phase_inc / uhd::math::PI) * 8192.0); _siggen_reg_iface.poke32( REG_PHASE_INC_OFFSET, phase_inc_scaled_rads_fp & 0xffff, port); }); diff --git a/host/tests/rfnoc_block_tests/siggen_block_test.cpp b/host/tests/rfnoc_block_tests/siggen_block_test.cpp index d495e7a19..6fdcb903b 100644 --- a/host/tests/rfnoc_block_tests/siggen_block_test.cpp +++ b/host/tests/rfnoc_block_tests/siggen_block_test.cpp @@ -4,8 +4,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#define _USE_MATH_DEFINES - #include "../rfnoc_graph_mock_nodes.hpp" #include <uhd/rfnoc/actions.hpp> #include <uhd/rfnoc/defaults.hpp> @@ -13,11 +11,11 @@ #include <uhd/rfnoc/multichan_register_iface.hpp> #include <uhd/rfnoc/register_iface_holder.hpp> #include <uhd/rfnoc/siggen_block_control.hpp> +#include <uhd/utils/math.hpp> #include <uhdlib/rfnoc/graph.hpp> #include <uhdlib/rfnoc/node_accessor.hpp> #include <uhdlib/utils/narrow.hpp> #include <boost/test/unit_test.hpp> -#include <cmath> #include <iostream> using namespace uhd::rfnoc; @@ -125,7 +123,7 @@ public: static uint32_t phase_increment_to_register(double phase_inc) { const int16_t phase_inc_scaled_rads_fp = - clamp<int16_t>((phase_inc / M_PI) * 8192.0); + clamp<int16_t>((phase_inc / uhd::math::PI) * 8192.0); return static_cast<uint32_t>(phase_inc_scaled_rads_fp) & 0xffff; } @@ -248,7 +246,7 @@ BOOST_FIXTURE_TEST_CASE(siggen_test_api, siggen_block_fixture) BOOST_CHECK_EQUAL(reg_iface->constants.at(port), siggen_mock_reg_iface_t::constant_to_register(constant)); BOOST_CHECK_EQUAL(test_siggen->get_constant(port), constant); - const double phase_inc = (port * M_PI / 16.0); + const double phase_inc = (port * uhd::math::PI / 16.0); test_siggen->set_sine_phase_increment(phase_inc, port); BOOST_CHECK_EQUAL(reg_iface->phase_increments.at(port), siggen_mock_reg_iface_t::phase_increment_to_register(phase_inc)); BOOST_CHECK_EQUAL(test_siggen->get_sine_phase_increment(port), phase_inc); @@ -256,7 +254,7 @@ BOOST_FIXTURE_TEST_CASE(siggen_test_api, siggen_block_fixture) const double freq = 1000 + (100 * port); const double samp_rate = 1e6; test_siggen->set_sine_frequency(freq, samp_rate, port); - const double calculated_phase_inc = freq / samp_rate * 2.0 * M_PI; + const double calculated_phase_inc = freq / samp_rate * 2.0 * uhd::math::PI; BOOST_CHECK_EQUAL(reg_iface->phase_increments.at(port), siggen_mock_reg_iface_t::phase_increment_to_register(calculated_phase_inc)); BOOST_CHECK_EQUAL( @@ -294,7 +292,7 @@ BOOST_FIXTURE_TEST_CASE(siggen_test_ranges, siggen_block_fixture) BOOST_CHECK_THROW(test_siggen->set_constant(bad_constant_q, port), uhd::value_error); BOOST_CHECK_THROW(test_siggen->set_constant(-bad_constant_q, port), uhd::value_error); - const double bad_phase_inc = 5 * M_PI; + const double bad_phase_inc = 5 * uhd::math::PI; BOOST_CHECK_THROW( test_siggen->set_sine_phase_increment(bad_phase_inc, port), uhd::value_error); BOOST_CHECK_THROW(test_siggen->set_sine_phase_increment(-bad_phase_inc, port), |