diff options
author | Ben Hilburn <ben.hilburn@ettus.com> | 2014-06-27 17:44:04 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2014-10-07 14:56:47 +0200 |
commit | 800f58430fdc577a2edd717d27b5902f75a1b1e4 (patch) | |
tree | e8436d8e008ab5e2220e67dbea1c4ee44d620cef /host/lib | |
parent | 4448843ca7392e2e5fbd44d6af12e69e6d465e00 (diff) | |
download | uhd-800f58430fdc577a2edd717d27b5902f75a1b1e4.tar.gz uhd-800f58430fdc577a2edd717d27b5902f75a1b1e4.tar.bz2 uhd-800f58430fdc577a2edd717d27b5902f75a1b1e4.zip |
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
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/usrp/cores/rx_dsp_core_200.cpp | 12 | ||||
-rw-r--r-- | host/lib/usrp/cores/rx_dsp_core_3000.cpp | 12 | ||||
-rw-r--r-- | host/lib/usrp/cores/tx_dsp_core_200.cpp | 12 | ||||
-rw-r--r-- | host/lib/usrp/cores/tx_dsp_core_3000.cpp | 12 |
4 files changed, 20 insertions, 28 deletions
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 <uhd/types/dict.hpp> #include <uhd/exception.hpp> +#include <uhd/utils/math.hpp> #include <uhd/utils/msg.hpp> #include <uhd/utils/safe_call.hpp> -#include <uhd/utils/algorithm.hpp> #include <boost/assign/list_of.hpp> #include <boost/thread/thread.hpp> //thread sleep #include <boost/math/special_functions/round.hpp> @@ -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<boost::int32_t>::highest(); - static const boost::int32_t int_min = boost::numeric::bounds<boost::int32_t>::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<boost::int32_t>::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<boost::int32_t>::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 <uhd/types/dict.hpp> #include <uhd/exception.hpp> +#include <uhd/utils/math.hpp> #include <uhd/utils/msg.hpp> #include <uhd/utils/safe_call.hpp> -#include <uhd/utils/algorithm.hpp> #include <boost/assign/list_of.hpp> #include <boost/thread/thread.hpp> //thread sleep #include <boost/math/special_functions/round.hpp> @@ -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<boost::int32_t>::highest(); - static const boost::int32_t int_min = boost::numeric::bounds<boost::int32_t>::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<boost::int32_t>::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<boost::int32_t>::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 <uhd/types/dict.hpp> #include <uhd/exception.hpp> +#include <uhd/utils/math.hpp> #include <uhd/utils/msg.hpp> -#include <uhd/utils/algorithm.hpp> #include <boost/assign/list_of.hpp> #include <boost/math/special_functions/round.hpp> #include <boost/math/special_functions/sign.hpp> @@ -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<boost::int32_t>::highest(); - static const boost::int32_t int_min = boost::numeric::bounds<boost::int32_t>::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<boost::int32_t>::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<boost::int32_t>::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 <uhd/types/dict.hpp> #include <uhd/exception.hpp> +#include <uhd/utils/math.hpp> #include <uhd/utils/msg.hpp> -#include <uhd/utils/algorithm.hpp> #include <boost/assign/list_of.hpp> #include <boost/math/special_functions/round.hpp> #include <boost/math/special_functions/sign.hpp> @@ -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<boost::int32_t>::highest(); - static const boost::int32_t int_min = boost::numeric::bounds<boost::int32_t>::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<boost::int32_t>::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<boost::int32_t>::lowest(); + freq_word = uhd::math::BOOST_INT32_MIN; } else { /* The operation is safe. Perform normally. */ |