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/rhodium/rhodium_bands.cpp | |
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/rhodium/rhodium_bands.cpp')
-rw-r--r-- | host/lib/usrp/dboard/rhodium/rhodium_bands.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/host/lib/usrp/dboard/rhodium/rhodium_bands.cpp b/host/lib/usrp/dboard/rhodium/rhodium_bands.cpp index 73f1bbe0c..6c16a7d7f 100644 --- a/host/lib/usrp/dboard/rhodium/rhodium_bands.cpp +++ b/host/lib/usrp/dboard/rhodium/rhodium_bands.cpp @@ -69,7 +69,7 @@ constexpr double RHODIUM_TX_BAND7_MIN_FREQ = 4100e6; rhodium_radio_control_impl::rx_band rhodium_radio_control_impl::_map_freq_to_rx_band( const double freq) { - auto freq_compare = fp_compare_epsilon<double>(freq, RHODIUM_FREQ_COMPARE_EPSILON); + const auto freq_compare = freq_compare_epsilon(freq); if (freq_compare < RHODIUM_RX_BAND0_MIN_FREQ) { return rx_band::RX_BAND_INVALID; @@ -97,7 +97,7 @@ rhodium_radio_control_impl::rx_band rhodium_radio_control_impl::_map_freq_to_rx_ rhodium_radio_control_impl::tx_band rhodium_radio_control_impl::_map_freq_to_tx_band( const double freq) { - auto freq_compare = fp_compare_epsilon<double>(freq, RHODIUM_FREQ_COMPARE_EPSILON); + const auto freq_compare = freq_compare_epsilon(freq); if (freq_compare < RHODIUM_TX_BAND0_MIN_FREQ) { return tx_band::TX_BAND_INVALID; |