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/tests | |
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/tests')
-rw-r--r-- | host/tests/fp_compare_epsilon_test.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/host/tests/fp_compare_epsilon_test.cpp b/host/tests/fp_compare_epsilon_test.cpp index 3aa973d3e..56cdd03e8 100644 --- a/host/tests/fp_compare_epsilon_test.cpp +++ b/host/tests/fp_compare_epsilon_test.cpp @@ -258,3 +258,13 @@ BOOST_AUTO_TEST_CASE(double_greaterthanequals_operators) BOOST_CHECK(charlie >= alpha); BOOST_CHECK(double(alpha._value + 3.0008) >= alpha); } + +BOOST_AUTO_TEST_CASE(frequency_comparison) +{ + // Delta comparison + BOOST_CHECK(uhd::math::frequencies_are_equal( + 1e9, 1e9 + uhd::math::FREQ_COMPARISON_DELTA_HZ / 10)); + // Epsilon comparison below 1 mHz + BOOST_CHECK( + freq_compare_epsilon(1e9) == (1e9 + uhd::math::FREQ_COMPARE_EPSILON / 10)); +} |