diff options
author | Martin Braun <martin.braun@ettus.com> | 2022-01-12 14:47:54 +0100 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2022-02-04 13:16:00 -0600 |
commit | 42ff4fb7f5a3e37714f025473f95089bf1ff8c98 (patch) | |
tree | 6d70a54cd704c95149f4b2c03bf32505fe26014a /host/lib/usrp/dboard/magnesium | |
parent | 3e496cbda1d809d2ca15f69cfa231424bf47179f (diff) | |
download | uhd-42ff4fb7f5a3e37714f025473f95089bf1ff8c98.tar.gz uhd-42ff4fb7f5a3e37714f025473f95089bf1ff8c98.tar.bz2 uhd-42ff4fb7f5a3e37714f025473f95089bf1ff8c98.zip |
uhd: Harmonize fuzzy frequency comparisons
Throughout UHD, we often do floating-point comparisons for frequency
ranges that require resilience to floating point rounding errors. Most
of the time the checks look like this:
```cpp
if (fp_compare_epsilon<double>(freq) > boundary) {
// ...
}
```
The exception is the N320 daughterboard control, which uses a custom
epsilon:
```cpp
if (fp_compare_epsilon<double>(freq,
RHODIUM_FREQ_COMPARE_EPSILON) > boundary) {
// ...
}
```
This was, for the most part, not by design, but because authors simply
didn't think about which epsilon value was appropriate for the frequency
comparison. This was complicated by the fact that fp_compare_epsilon
previously had some issues.
This patch introduces FREQ_COMPARE_EPSILON, which is a sensible default
value for fp_compare_epsilon when doing frequency comparisons (note that
fp_compare_delta already had such a value).
Also, it introduces freq_compare_epsilon(x), which is a shorthand for
fp_compare_epsilon<double>(x, FREQ_COMPARE_EPSILON).
We then replace all occurrences of fp_compare_epsilon<double> which are
specific to frequency checks with freq_compare_epsilon.
Diffstat (limited to 'host/lib/usrp/dboard/magnesium')
-rw-r--r-- | host/lib/usrp/dboard/magnesium/magnesium_bands.cpp | 30 | ||||
-rw-r--r-- | host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp | 4 |
2 files changed, 17 insertions, 17 deletions
diff --git a/host/lib/usrp/dboard/magnesium/magnesium_bands.cpp b/host/lib/usrp/dboard/magnesium/magnesium_bands.cpp index ef72aee95..b54bf9a62 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_bands.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_bands.cpp @@ -98,23 +98,23 @@ magnesium_radio_control_impl::rx_band magnesium_radio_control_impl::_map_freq_to { magnesium_radio_control_impl::rx_band band; - if (fp_compare_epsilon<double>(freq) < MAGNESIUM_MIN_FREQ) { + if (freq_compare_epsilon(freq) < MAGNESIUM_MIN_FREQ) { band = rx_band::INVALID_BAND; - } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) { + } else if (freq_compare_epsilon(freq) < MAGNESIUM_LOWBAND_FREQ) { band = rx_band::LOWBAND; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(1)) { + } else if (freq_compare_epsilon(freq) < band_map.at(1)) { band = rx_band::BAND0; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(2)) { + } else if (freq_compare_epsilon(freq) < band_map.at(2)) { band = rx_band::BAND1; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(3)) { + } else if (freq_compare_epsilon(freq) < band_map.at(3)) { band = rx_band::BAND2; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(4)) { + } else if (freq_compare_epsilon(freq) < band_map.at(4)) { band = rx_band::BAND3; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(5)) { + } else if (freq_compare_epsilon(freq) < band_map.at(5)) { band = rx_band::BAND4; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(6)) { + } else if (freq_compare_epsilon(freq) < band_map.at(6)) { band = rx_band::BAND5; - } else if (fp_compare_epsilon<double>(freq) <= MAGNESIUM_MAX_FREQ) { + } else if (freq_compare_epsilon(freq) <= MAGNESIUM_MAX_FREQ) { band = rx_band::BAND6; } else { band = rx_band::INVALID_BAND; @@ -128,17 +128,17 @@ magnesium_radio_control_impl::tx_band magnesium_radio_control_impl::_map_freq_to { magnesium_radio_control_impl::tx_band band; - if (fp_compare_epsilon<double>(freq) < MAGNESIUM_MIN_FREQ) { + if (freq_compare_epsilon(freq) < MAGNESIUM_MIN_FREQ) { band = tx_band::INVALID_BAND; - } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) { + } else if (freq_compare_epsilon(freq) < MAGNESIUM_LOWBAND_FREQ) { band = tx_band::LOWBAND; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(1)) { + } else if (freq_compare_epsilon(freq) < band_map.at(1)) { band = tx_band::BAND0; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(2)) { + } else if (freq_compare_epsilon(freq) < band_map.at(2)) { band = tx_band::BAND1; - } else if (fp_compare_epsilon<double>(freq) < band_map.at(3)) { + } else if (freq_compare_epsilon(freq) < band_map.at(3)) { band = tx_band::BAND2; - } else if (fp_compare_epsilon<double>(freq) <= MAGNESIUM_MAX_FREQ) { + } else if (freq_compare_epsilon(freq) <= MAGNESIUM_MAX_FREQ) { band = tx_band::BAND3; } else { band = tx_band::INVALID_BAND; diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp index 441e7b427..637d85d49 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp @@ -299,8 +299,8 @@ void magnesium_radio_control_impl::_update_freq( : ad9371_freq; RFNOC_LOG_TRACE("RF freq = " << rf_freq); - UHD_ASSERT_THROW(fp_compare_epsilon<double>(rf_freq) >= 0); - UHD_ASSERT_THROW(fp_compare_epsilon<double>(std::abs(rf_freq - _desired_rf_freq[dir])) + UHD_ASSERT_THROW(freq_compare_epsilon(rf_freq) >= 0); + UHD_ASSERT_THROW(freq_compare_epsilon(std::abs(rf_freq - _desired_rf_freq[dir])) <= _master_clock_rate / 2); if (dir == RX_DIRECTION) { radio_control_impl::set_rx_frequency(rf_freq, chan); |