From a151a7b78349bfe7954c664154dd59b70171b348 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 7 May 2015 11:55:36 -0700 Subject: b200: Replaced float comparisons with uhd::math::fp* operations --- host/lib/usrp/b200/b200_io_impl.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/host/lib/usrp/b200/b200_io_impl.cpp b/host/lib/usrp/b200/b200_io_impl.cpp index 61bcc5f64..71a103cfe 100644 --- a/host/lib/usrp/b200/b200_io_impl.cpp +++ b/host/lib/usrp/b200/b200_io_impl.cpp @@ -96,7 +96,10 @@ void b200_impl::set_auto_tick_rate( } double this_dsp_rate = _tree->access(dsp_path / "rate/value").get(); // Check if the user selected something completely unreasonable: - if (this_dsp_rate > max_tick_rate) { + if (uhd::math::fp_compare::fp_compare_delta(this_dsp_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ) > + uhd::math::fp_compare::fp_compare_delta(max_tick_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ)) { + UHD_MSG(status) << boost::format("%.20d") % this_dsp_rate << std::endl; + UHD_MSG(status) << boost::format("%.20d") % max_tick_rate << std::endl; throw uhd::value_error(str( boost::format("Requested sampling rate (%.2f Msps) exceeds maximum tick rate of %.2f MHz.") % (this_dsp_rate / 1e6) % (max_tick_rate / 1e6) @@ -127,7 +130,8 @@ void b200_impl::set_auto_tick_rate( // Step 2: Determine whether if we can use lcm_rate (preferred), // or have to give up because too large: double base_rate = static_cast(lcm_rate); - if (base_rate > max_tick_rate) { + if (uhd::math::fp_compare::fp_compare_delta(base_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ) > + uhd::math::fp_compare::fp_compare_delta(max_tick_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ)) { UHD_MSG(warning) << "Cannot automatically determine an appropriate tick rate for these sampling rates." << std::endl << "Consider using different sampling rates, or manually specify a suitable master clock rate." << std::endl; @@ -154,8 +158,14 @@ void b200_impl::set_auto_tick_rate( multiplier = 1; } double new_rate = base_rate * multiplier; - UHD_ASSERT_THROW(new_rate >= min_tick_rate); - UHD_ASSERT_THROW(new_rate <= max_tick_rate); + UHD_ASSERT_THROW( + uhd::math::fp_compare::fp_compare_delta(new_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ) >= + uhd::math::fp_compare::fp_compare_delta(min_tick_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ) + ); + UHD_ASSERT_THROW( + uhd::math::fp_compare::fp_compare_delta(new_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ) <= + uhd::math::fp_compare::fp_compare_delta(max_tick_rate, uhd::math::FREQ_COMPARISON_DELTA_HZ) + ); if (_tree->access("/mboards/0/tick_rate").get() != new_rate) { _tree->access("/mboards/0/tick_rate").set(new_rate); @@ -183,7 +193,8 @@ void b200_impl::update_tick_rate(const double new_tick_rate) } #define CHECK_RATE_AND_THROW(rate) \ - if (rate >ad9361_device_t::AD9361_MAX_CLOCK_RATE ) { \ + if (uhd::math::fp_compare::fp_compare_delta(rate, uhd::math::FREQ_COMPARISON_DELTA_HZ) > \ + uhd::math::fp_compare::fp_compare_delta(ad9361_device_t::AD9361_MAX_CLOCK_RATE, uhd::math::FREQ_COMPARISON_DELTA_HZ)) { \ throw uhd::value_error(str( \ boost::format("Requested sampling rate (%.2f Msps) exceeds maximum tick rate.") \ % (rate / 1e6) \ -- cgit v1.2.3