From 800f58430fdc577a2edd717d27b5902f75a1b1e4 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Fri, 27 Jun 2014 17:44:04 -0700 Subject: math: Added a new uhd::math namespace + float comparison routines * Float comparison is applied to tuning logic in DSP cores. * Properly using INT_MAX/MIN constants, defined in utils/math.hpp --- host/lib/usrp/cores/rx_dsp_core_200.cpp | 12 +++++------- host/lib/usrp/cores/rx_dsp_core_3000.cpp | 12 +++++------- host/lib/usrp/cores/tx_dsp_core_200.cpp | 12 +++++------- host/lib/usrp/cores/tx_dsp_core_3000.cpp | 12 +++++------- 4 files changed, 20 insertions(+), 28 deletions(-) (limited to 'host/lib/usrp') diff --git a/host/lib/usrp/cores/rx_dsp_core_200.cpp b/host/lib/usrp/cores/rx_dsp_core_200.cpp index 160124b3e..6a36e8fa1 100644 --- a/host/lib/usrp/cores/rx_dsp_core_200.cpp +++ b/host/lib/usrp/cores/rx_dsp_core_200.cpp @@ -18,9 +18,9 @@ #include "rx_dsp_core_200.hpp" #include #include +#include #include #include -#include #include #include //thread sleep #include @@ -242,15 +242,13 @@ public: boost::int32_t freq_word = 0; static const double scale_factor = std::pow(2.0, 32); - static const boost::int32_t int_max = boost::numeric::bounds::highest(); - static const boost::int32_t int_min = boost::numeric::bounds::lowest(); - if((freq / _tick_rate) >= (int_max / scale_factor)) { + if((freq / _tick_rate) >= (uhd::math::BOOST_INT32_MAX / scale_factor)) { /* Operation would have caused a positive overflow of int32. */ - freq_word = boost::numeric::bounds::highest(); + freq_word = uhd::math::BOOST_INT32_MAX; - } else if((freq / _tick_rate) <= (int_min / scale_factor)) { + } else if((freq / _tick_rate) <= (uhd::math::BOOST_INT32_MIN / scale_factor)) { /* Operation would have caused a negative overflow of int32. */ - freq_word = boost::numeric::bounds::lowest(); + freq_word = uhd::math::BOOST_INT32_MIN; } else { /* The operation is safe. Perform normally. */ diff --git a/host/lib/usrp/cores/rx_dsp_core_3000.cpp b/host/lib/usrp/cores/rx_dsp_core_3000.cpp index 6ce3c1d32..32866880f 100644 --- a/host/lib/usrp/cores/rx_dsp_core_3000.cpp +++ b/host/lib/usrp/cores/rx_dsp_core_3000.cpp @@ -18,9 +18,9 @@ #include "rx_dsp_core_3000.hpp" #include #include +#include #include #include -#include #include #include //thread sleep #include @@ -210,15 +210,13 @@ public: boost::int32_t freq_word = 0; static const double scale_factor = std::pow(2.0, 32); - static const boost::int32_t int_max = boost::numeric::bounds::highest(); - static const boost::int32_t int_min = boost::numeric::bounds::lowest(); - if((freq / _tick_rate) >= (int_max / scale_factor)) { + if((freq / _tick_rate) >= (uhd::math::BOOST_INT32_MAX / scale_factor)) { /* Operation would have caused a positive overflow of int32. */ - freq_word = boost::numeric::bounds::highest(); + freq_word = uhd::math::BOOST_INT32_MAX; - } else if((freq / _tick_rate) <= (int_min / scale_factor)) { + } else if((freq / _tick_rate) <= (uhd::math::BOOST_INT32_MIN / scale_factor)) { /* Operation would have caused a negative overflow of int32. */ - freq_word = boost::numeric::bounds::lowest(); + freq_word = uhd::math::BOOST_INT32_MIN; } else { /* The operation is safe. Perform normally. */ diff --git a/host/lib/usrp/cores/tx_dsp_core_200.cpp b/host/lib/usrp/cores/tx_dsp_core_200.cpp index 3f397dd6a..2ef9f4406 100644 --- a/host/lib/usrp/cores/tx_dsp_core_200.cpp +++ b/host/lib/usrp/cores/tx_dsp_core_200.cpp @@ -18,8 +18,8 @@ #include "tx_dsp_core_200.hpp" #include #include +#include #include -#include #include #include #include @@ -182,15 +182,13 @@ public: boost::int32_t freq_word = 0; static const double scale_factor = std::pow(2.0, 32); - static const boost::int32_t int_max = boost::numeric::bounds::highest(); - static const boost::int32_t int_min = boost::numeric::bounds::lowest(); - if((freq / _tick_rate) >= (int_max / scale_factor)) { + if((freq / _tick_rate) >= (uhd::math::BOOST_INT32_MAX / scale_factor)) { /* Operation would have caused a positive overflow of int32. */ - freq_word = boost::numeric::bounds::highest(); + freq_word = uhd::math::BOOST_INT32_MAX; - } else if((freq / _tick_rate) <= (int_min / scale_factor)) { + } else if((freq / _tick_rate) <= (uhd::math::BOOST_INT32_MIN / scale_factor)) { /* Operation would have caused a negative overflow of int32. */ - freq_word = boost::numeric::bounds::lowest(); + freq_word = uhd::math::BOOST_INT32_MIN; } else { /* The operation is safe. Perform normally. */ diff --git a/host/lib/usrp/cores/tx_dsp_core_3000.cpp b/host/lib/usrp/cores/tx_dsp_core_3000.cpp index 0dc19f2c8..736205402 100644 --- a/host/lib/usrp/cores/tx_dsp_core_3000.cpp +++ b/host/lib/usrp/cores/tx_dsp_core_3000.cpp @@ -18,8 +18,8 @@ #include "tx_dsp_core_3000.hpp" #include #include +#include #include -#include #include #include #include @@ -147,15 +147,13 @@ public: boost::int32_t freq_word = 0; static const double scale_factor = std::pow(2.0, 32); - static const boost::int32_t int_max = boost::numeric::bounds::highest(); - static const boost::int32_t int_min = boost::numeric::bounds::lowest(); - if((freq / _tick_rate) >= (int_max / scale_factor)) { + if((freq / _tick_rate) >= (uhd::math::BOOST_INT32_MAX / scale_factor)) { /* Operation would have caused a positive overflow of int32. */ - freq_word = boost::numeric::bounds::highest(); + freq_word = uhd::math::BOOST_INT32_MAX; - } else if((freq / _tick_rate) <= (int_min / scale_factor)) { + } else if((freq / _tick_rate) <= (uhd::math::BOOST_INT32_MIN / scale_factor)) { /* Operation would have caused a negative overflow of int32. */ - freq_word = boost::numeric::bounds::lowest(); + freq_word = uhd::math::BOOST_INT32_MIN; } else { /* The operation is safe. Perform normally. */ -- cgit v1.2.3