From 42ff4fb7f5a3e37714f025473f95089bf1ff8c98 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 12 Jan 2022 14:47:54 +0100 Subject: 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(freq) > boundary) { // ... } ``` The exception is the N320 daughterboard control, which uses a custom epsilon: ```cpp if (fp_compare_epsilon(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(x, FREQ_COMPARE_EPSILON). We then replace all occurrences of fp_compare_epsilon which are specific to frequency checks with freq_compare_epsilon. --- host/lib/usrp/dboard/e3xx/e3xx_bands.cpp | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'host/lib/usrp/dboard/e3xx') diff --git a/host/lib/usrp/dboard/e3xx/e3xx_bands.cpp b/host/lib/usrp/dboard/e3xx/e3xx_bands.cpp index e28acf3b9..e9226216b 100644 --- a/host/lib/usrp/dboard/e3xx/e3xx_bands.cpp +++ b/host/lib/usrp/dboard/e3xx/e3xx_bands.cpp @@ -146,21 +146,21 @@ e3xx_radio_control_impl::rx_band e3xx_radio_control_impl::map_freq_to_rx_band( { e3xx_radio_control_impl::rx_band band; - if (fp_compare_epsilon(freq) < AD9361_RX_MIN_FREQ) { + if (freq_compare_epsilon(freq) < AD9361_RX_MIN_FREQ) { band = rx_band::INVALID_BAND; - } else if (fp_compare_epsilon(freq) < E3XX_RX_LB_BAND3_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_RX_LB_BAND3_MIN_FREQ) { band = rx_band::LB_B2; - } else if (fp_compare_epsilon(freq) < E3XX_RX_LB_BAND4_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_RX_LB_BAND4_MIN_FREQ) { band = rx_band::LB_B3; - } else if (fp_compare_epsilon(freq) < E3XX_RX_LB_BAND5_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_RX_LB_BAND5_MIN_FREQ) { band = rx_band::LB_B4; - } else if (fp_compare_epsilon(freq) < E3XX_RX_LB_BAND6_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_RX_LB_BAND6_MIN_FREQ) { band = rx_band::LB_B5; - } else if (fp_compare_epsilon(freq) < E3XX_RX_LB_BAND7_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_RX_LB_BAND7_MIN_FREQ) { band = rx_band::LB_B6; - } else if (fp_compare_epsilon(freq) < E3XX_RX_HB_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_RX_HB_MIN_FREQ) { band = rx_band::LB_B7; - } else if (fp_compare_epsilon(freq) <= AD9361_RX_MAX_FREQ) { + } else if (freq_compare_epsilon(freq) <= AD9361_RX_MAX_FREQ) { band = rx_band::HB; } else { band = rx_band::INVALID_BAND; @@ -174,25 +174,25 @@ e3xx_radio_control_impl::tx_band e3xx_radio_control_impl::map_freq_to_tx_band( { e3xx_radio_control_impl::tx_band band; - if (fp_compare_epsilon(freq) < AD9361_TX_MIN_FREQ) { + if (freq_compare_epsilon(freq) < AD9361_TX_MIN_FREQ) { band = tx_band::INVALID_BAND; - } else if (fp_compare_epsilon(freq) < E3XX_TX_LB_160_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_LB_160_MIN_FREQ) { band = tx_band::LB_80; - } else if (fp_compare_epsilon(freq) < E3XX_TX_LB_225_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_LB_225_MIN_FREQ) { band = tx_band::LB_160; - } else if (fp_compare_epsilon(freq) < E3XX_TX_LB_400_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_LB_400_MIN_FREQ) { band = tx_band::LB_225; - } else if (fp_compare_epsilon(freq) < E3XX_TX_LB_575_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_LB_575_MIN_FREQ) { band = tx_band::LB_400; - } else if (fp_compare_epsilon(freq) < E3XX_TX_LB_1000_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_LB_1000_MIN_FREQ) { band = tx_band::LB_575; - } else if (fp_compare_epsilon(freq) < E3XX_TX_LB_1700_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_LB_1700_MIN_FREQ) { band = tx_band::LB_1000; - } else if (fp_compare_epsilon(freq) < E3XX_TX_LB_2750_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_LB_2750_MIN_FREQ) { band = tx_band::LB_1700; - } else if (fp_compare_epsilon(freq) < E3XX_TX_HB_MIN_FREQ) { + } else if (freq_compare_epsilon(freq) < E3XX_TX_HB_MIN_FREQ) { band = tx_band::LB_2750; - } else if (fp_compare_epsilon(freq) <= AD9361_TX_MAX_FREQ) { + } else if (freq_compare_epsilon(freq) <= AD9361_TX_MAX_FREQ) { band = tx_band::HB; } else { band = tx_band::INVALID_BAND; -- cgit v1.2.3