From aae93861a042e18b34871e36e8e66004f777396a Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 22 Apr 2016 09:44:20 -0700 Subject: math: Fixed floating point comparison for custom delta Reviewed-By: Derek Kozel --- host/include/uhd/utils/fp_compare_delta.ipp | 2 +- host/tests/fp_compare_delta_test.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/host/include/uhd/utils/fp_compare_delta.ipp b/host/include/uhd/utils/fp_compare_delta.ipp index 49cbc281b..292ef4bf6 100644 --- a/host/include/uhd/utils/fp_compare_delta.ipp +++ b/host/include/uhd/utils/fp_compare_delta.ipp @@ -27,7 +27,7 @@ namespace uhd { namespace math { namespace fp_compare { template UHD_INLINE float_t fp_compare_select_delta(float_t lhs_delta, float_t rhs_delta) { - return ((lhs_delta < rhs_delta) ? lhs_delta : rhs_delta); + return ((lhs_delta > rhs_delta) ? lhs_delta : rhs_delta); } template<> UHD_INLINE diff --git a/host/tests/fp_compare_delta_test.cpp b/host/tests/fp_compare_delta_test.cpp index 36ff14756..d6d8a5209 100644 --- a/host/tests/fp_compare_delta_test.cpp +++ b/host/tests/fp_compare_delta_test.cpp @@ -237,6 +237,14 @@ BOOST_AUTO_TEST_CASE(double_greaterthanequals_operators) { BOOST_CHECK(double(alpha._value + 3.0008) >= alpha); } +BOOST_AUTO_TEST_CASE(fp_compare_large_delta) { + BOOST_CHECK(fp_compare_delta(61440000.047870710492, 0.1) == 61440000.000000000000); + BOOST_CHECK(fp_compare_delta(61440000.047870710492, 0.1) <= 61440000.000000000000); + BOOST_CHECK(fp_compare_delta(61440000.047870710492, 0.1) >= 61440000.000000000000); + + BOOST_CHECK(fp_compare_delta(1.0, 10.0) == 2.0); +} + BOOST_AUTO_TEST_CASE(frequency_compare_function) { BOOST_CHECK(uhd::math::frequencies_are_equal(6817333232.0, 6817333232.0)); -- cgit v1.2.3