diff --git a/include/internal/catch_matchers_floating.cpp b/include/internal/catch_matchers_floating.cpp index 9bc082ed..d001b751 100644 --- a/include/internal/catch_matchers_floating.cpp +++ b/include/internal/catch_matchers_floating.cpp @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include namespace Catch { namespace Matchers { @@ -74,8 +77,16 @@ bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { return ulpDiff <= maxUlpDiff; } +template +FP step(FP start, FP direction, int steps) { + for (int i = 0; i < steps; ++i) { + start = std::nextafter(start, direction); + } + return start; } +} // end anonymous namespace + namespace Catch { namespace Matchers { @@ -125,7 +136,29 @@ namespace Floating { #endif std::string WithinUlpsMatcher::describe() const { - return "is within " + Catch::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : ""); + std::stringstream ret; + + ret << "is within " << m_ulps << " ULPs of " << ::Catch::Detail::stringify(m_target); + + if (m_type == FloatingPointKind::Float) { + ret << 'f'; + } + + ret << " (["; + ret << std::fixed << std::setprecision(std::numeric_limits::max_digits10); + if (m_type == FloatingPointKind::Double) { + ret << step(m_target, static_cast(-INFINITY), m_ulps) + << ", " + << step(m_target, static_cast(INFINITY), m_ulps); + } else { + ret << step(static_cast(m_target), -INFINITY, m_ulps) + << ", " + << step(static_cast(m_target), INFINITY, m_ulps); + } + ret << "])"; + + return ret.str(); + //return "is within " + Catch::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : ""); } }// namespace Floating diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index eb30151f..88aec96a 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -396,21 +396,18 @@ Matchers.tests.cpp:: passed: 1., WithinAbs(1., 0) for: 1.0 is withi Matchers.tests.cpp:: passed: 0., WithinAbs(1., 1) for: 0.0 is within 1.0 of 1.0 Matchers.tests.cpp:: passed: 0., !WithinAbs(1., 0.99) for: 0.0 not is within 0.99 of 1.0 Matchers.tests.cpp:: passed: 0., !WithinAbs(1., 0.99) for: 0.0 not is within 0.99 of 1.0 -Matchers.tests.cpp:: passed: NAN, !WithinAbs(NAN, 0) for: nanf not is within 0.0 of nan Matchers.tests.cpp:: passed: 11., !WithinAbs(10., 0.5) for: 11.0 not is within 0.5 of 10.0 Matchers.tests.cpp:: passed: 10., !WithinAbs(11., 0.5) for: 10.0 not is within 0.5 of 11.0 Matchers.tests.cpp:: passed: -10., WithinAbs(-10., 0.5) for: -10.0 is within 0.5 of -10.0 Matchers.tests.cpp:: passed: -10., WithinAbs(-9.6, 0.5) for: -10.0 is within 0.5 of -9.6 -Matchers.tests.cpp:: passed: 1., WithinULP(1., 0) for: 1.0 is within 0 ULPs of 1.0 -Matchers.tests.cpp:: passed: nextafter(1., 2.), WithinULP(1., 1) for: 1.0 is within 1 ULPs of 1.0 -Matchers.tests.cpp:: passed: nextafter(1., 0.), WithinULP(1., 1) for: 1.0 is within 1 ULPs of 1.0 -Matchers.tests.cpp:: passed: nextafter(1., 2.), !WithinULP(1., 0) for: 1.0 not is within 0 ULPs of 1.0 -Matchers.tests.cpp:: passed: 1., WithinULP(1., 0) for: 1.0 is within 0 ULPs of 1.0 -Matchers.tests.cpp:: passed: -0., WithinULP(0., 0) for: -0.0 is within 0 ULPs of 0.0 -Matchers.tests.cpp:: passed: NAN, !WithinULP(NAN, 123) for: nanf not is within 123 ULPs of nanf -Matchers.tests.cpp:: passed: 1., WithinAbs(1., 0.5) || WithinULP(2., 1) for: 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ) -Matchers.tests.cpp:: passed: 1., WithinAbs(2., 0.5) || WithinULP(1., 0) for: 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ) -Matchers.tests.cpp:: passed: NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) for: nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) +Matchers.tests.cpp:: passed: 1., WithinULP(1., 0) for: 1.0 is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) +Matchers.tests.cpp:: passed: nextafter(1., 2.), WithinULP(1., 1) for: 1.0 is within 1 ULPs of 1.0 ([0.99999999999999989, 1.00000000000000022]) +Matchers.tests.cpp:: passed: nextafter(1., 0.), WithinULP(1., 1) for: 1.0 is within 1 ULPs of 1.0 ([0.99999999999999989, 1.00000000000000022]) +Matchers.tests.cpp:: passed: nextafter(1., 2.), !WithinULP(1., 0) for: 1.0 not is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) +Matchers.tests.cpp:: passed: 1., WithinULP(1., 0) for: 1.0 is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) +Matchers.tests.cpp:: passed: -0., WithinULP(0., 0) for: -0.0 is within 0 ULPs of 0.0 ([0.00000000000000000, 0.00000000000000000]) +Matchers.tests.cpp:: passed: 1., WithinAbs(1., 0.5) || WithinULP(2., 1) for: 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ([1.99999999999999978, 2.00000000000000044]) ) +Matchers.tests.cpp:: passed: 1., WithinAbs(2., 0.5) || WithinULP(1., 0) for: 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) ) Matchers.tests.cpp:: passed: WithinAbs(1., 0.) Matchers.tests.cpp:: passed: WithinAbs(1., -1.), std::domain_error Matchers.tests.cpp:: passed: WithinULP(1., 0) @@ -420,21 +417,18 @@ Matchers.tests.cpp:: passed: 0.f, WithinAbs(1.f, 1) for: 0.0f is wi Matchers.tests.cpp:: passed: 0.f, !WithinAbs(1.f, 0.99f) for: 0.0f not is within 0.9900000095 of 1.0 Matchers.tests.cpp:: passed: 0.f, !WithinAbs(1.f, 0.99f) for: 0.0f not is within 0.9900000095 of 1.0 Matchers.tests.cpp:: passed: 0.f, WithinAbs(-0.f, 0) for: 0.0f is within 0.0 of -0.0 -Matchers.tests.cpp:: passed: NAN, !WithinAbs(NAN, 0) for: nanf not is within 0.0 of nan Matchers.tests.cpp:: passed: 11.f, !WithinAbs(10.f, 0.5f) for: 11.0f not is within 0.5 of 10.0 Matchers.tests.cpp:: passed: 10.f, !WithinAbs(11.f, 0.5f) for: 10.0f not is within 0.5 of 11.0 Matchers.tests.cpp:: passed: -10.f, WithinAbs(-10.f, 0.5f) for: -10.0f is within 0.5 of -10.0 Matchers.tests.cpp:: passed: -10.f, WithinAbs(-9.6f, 0.5f) for: -10.0f is within 0.5 of -9.6000003815 -Matchers.tests.cpp:: passed: 1.f, WithinULP(1.f, 0) for: 1.0f is within 0 ULPs of 1.0f -Matchers.tests.cpp:: passed: nextafter(1.f, 2.f), WithinULP(1.f, 1) for: 1.0f is within 1 ULPs of 1.0f -Matchers.tests.cpp:: passed: nextafter(1.f, 0.f), WithinULP(1.f, 1) for: 1.0f is within 1 ULPs of 1.0f -Matchers.tests.cpp:: passed: nextafter(1.f, 2.f), !WithinULP(1.f, 0) for: 1.0f not is within 0 ULPs of 1.0f -Matchers.tests.cpp:: passed: 1.f, WithinULP(1.f, 0) for: 1.0f is within 0 ULPs of 1.0f -Matchers.tests.cpp:: passed: -0.f, WithinULP(0.f, 0) for: -0.0f is within 0 ULPs of 0.0f -Matchers.tests.cpp:: passed: NAN, !WithinULP(NAN, 123) for: nanf not is within 123 ULPs of nanf -Matchers.tests.cpp:: passed: 1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1) for: 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ) -Matchers.tests.cpp:: passed: 1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0) for: 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ) -Matchers.tests.cpp:: passed: NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) for: nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) +Matchers.tests.cpp:: passed: 1.f, WithinULP(1.f, 0) for: 1.0f is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) +Matchers.tests.cpp:: passed: nextafter(1.f, 2.f), WithinULP(1.f, 1) for: 1.0f is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) +Matchers.tests.cpp:: passed: nextafter(1.f, 0.f), WithinULP(1.f, 1) for: 1.0f is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) +Matchers.tests.cpp:: passed: nextafter(1.f, 2.f), !WithinULP(1.f, 0) for: 1.0f not is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) +Matchers.tests.cpp:: passed: 1.f, WithinULP(1.f, 0) for: 1.0f is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) +Matchers.tests.cpp:: passed: -0.f, WithinULP(0.f, 0) for: -0.0f is within 0 ULPs of 0.0f ([0.00000000000000000, 0.00000000000000000]) +Matchers.tests.cpp:: passed: 1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1) for: 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) ) +Matchers.tests.cpp:: passed: 1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0) for: 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) ) Matchers.tests.cpp:: passed: WithinAbs(1.f, 0.f) Matchers.tests.cpp:: passed: WithinAbs(1.f, -1.f), std::domain_error Matchers.tests.cpp:: passed: WithinULP(1.f, 0) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index ebbef313..37541e89 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 289 | 215 passed | 70 failed | 4 failed as expected -assertions: 1547 | 1395 passed | 131 failed | 21 failed as expected +assertions: 1541 | 1389 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 3ff1e189..37dbf19b 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -2949,11 +2949,6 @@ Matchers.tests.cpp:: PASSED: with expansion: 0.0 not is within 0.99 of 1.0 -Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( NAN, !WithinAbs(NAN, 0) ) -with expansion: - nanf not is within 0.0 of nan - Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 11., !WithinAbs(10., 0.5) ) with expansion: @@ -2984,37 +2979,32 @@ Matchers.tests.cpp: Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1., WithinULP(1., 0) ) with expansion: - 1.0 is within 0 ULPs of 1.0 + 1.0 is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( nextafter(1., 2.), WithinULP(1., 1) ) with expansion: - 1.0 is within 1 ULPs of 1.0 + 1.0 is within 1 ULPs of 1.0 ([0.99999999999999989, 1.00000000000000022]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( nextafter(1., 0.), WithinULP(1., 1) ) with expansion: - 1.0 is within 1 ULPs of 1.0 + 1.0 is within 1 ULPs of 1.0 ([0.99999999999999989, 1.00000000000000022]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( nextafter(1., 2.), !WithinULP(1., 0) ) with expansion: - 1.0 not is within 0 ULPs of 1.0 + 1.0 not is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1., WithinULP(1., 0) ) with expansion: - 1.0 is within 0 ULPs of 1.0 + 1.0 is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( -0., WithinULP(0., 0) ) with expansion: - -0.0 is within 0 ULPs of 0.0 - -Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( NAN, !WithinULP(NAN, 123) ) -with expansion: - nanf not is within 123 ULPs of nanf + -0.0 is within 0 ULPs of 0.0 ([0.00000000000000000, 0.00000000000000000]) ------------------------------------------------------------------------------- Floating point matchers: double @@ -3026,17 +3016,14 @@ Matchers.tests.cpp: Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1., WithinAbs(1., 0.5) || WithinULP(2., 1) ) with expansion: - 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ) + 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ([1.99999999999999978, + 2.00000000000000044]) ) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1., WithinAbs(2., 0.5) || WithinULP(1., 0) ) with expansion: - 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ) - -Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) ) -with expansion: - nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) + 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ([1.00000000000000000, + 1.00000000000000000]) ) ------------------------------------------------------------------------------- Floating point matchers: double @@ -3089,11 +3076,6 @@ Matchers.tests.cpp:: PASSED: with expansion: 0.0f is within 0.0 of -0.0 -Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( NAN, !WithinAbs(NAN, 0) ) -with expansion: - nanf not is within 0.0 of nan - Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 11.f, !WithinAbs(10.f, 0.5f) ) with expansion: @@ -3124,37 +3106,33 @@ Matchers.tests.cpp: Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinULP(1.f, 0) ) with expansion: - 1.0f is within 0 ULPs of 1.0f + 1.0f is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( nextafter(1.f, 2.f), WithinULP(1.f, 1) ) with expansion: - 1.0f is within 1 ULPs of 1.0f + 1.0f is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( nextafter(1.f, 0.f), WithinULP(1.f, 1) ) with expansion: - 1.0f is within 1 ULPs of 1.0f + 1.0f is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( nextafter(1.f, 2.f), !WithinULP(1.f, 0) ) with expansion: - 1.0f not is within 0 ULPs of 1.0f + 1.0f not is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000] + ) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinULP(1.f, 0) ) with expansion: - 1.0f is within 0 ULPs of 1.0f + 1.0f is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( -0.f, WithinULP(0.f, 0) ) with expansion: - -0.0f is within 0 ULPs of 0.0f - -Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( NAN, !WithinULP(NAN, 123) ) -with expansion: - nanf not is within 123 ULPs of nanf + -0.0f is within 0 ULPs of 0.0f ([0.00000000000000000, 0.00000000000000000]) ------------------------------------------------------------------------------- Floating point matchers: float @@ -3166,17 +3144,14 @@ Matchers.tests.cpp: Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1) ) with expansion: - 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ) + 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ([0. + 99999994039535522, 1.00000011920928955]) ) Matchers.tests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0) ) with expansion: - 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ) - -Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) ) -with expansion: - nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) + 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ([1. + 00000000000000000, 1.00000000000000000]) ) ------------------------------------------------------------------------------- Floating point matchers: float @@ -12291,5 +12266,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 289 | 199 passed | 86 failed | 4 failed as expected -assertions: 1564 | 1395 passed | 148 failed | 21 failed as expected +assertions: 1558 | 1389 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 4592a90c..55c030de 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 0d306b2e..b8df94c9 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -3528,14 +3528,6 @@ Nor would this 0.0 not is within 0.99 of 1.0 - - - NAN, !WithinAbs(NAN, 0) - - - nanf not is within 0.0 of nan - - 11., !WithinAbs(10., 0.5) @@ -3568,7 +3560,7 @@ Nor would this -10.0 is within 0.5 of -9.6 - +
@@ -3576,7 +3568,7 @@ Nor would this 1., WithinULP(1., 0) - 1.0 is within 0 ULPs of 1.0 + 1.0 is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) @@ -3584,7 +3576,7 @@ Nor would this nextafter(1., 2.), WithinULP(1., 1) - 1.0 is within 1 ULPs of 1.0 + 1.0 is within 1 ULPs of 1.0 ([0.99999999999999989, 1.00000000000000022]) @@ -3592,7 +3584,7 @@ Nor would this nextafter(1., 0.), WithinULP(1., 1) - 1.0 is within 1 ULPs of 1.0 + 1.0 is within 1 ULPs of 1.0 ([0.99999999999999989, 1.00000000000000022]) @@ -3600,7 +3592,7 @@ Nor would this nextafter(1., 2.), !WithinULP(1., 0) - 1.0 not is within 0 ULPs of 1.0 + 1.0 not is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) @@ -3608,7 +3600,7 @@ Nor would this 1., WithinULP(1., 0) - 1.0 is within 0 ULPs of 1.0 + 1.0 is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) @@ -3616,18 +3608,10 @@ Nor would this -0., WithinULP(0., 0) - -0.0 is within 0 ULPs of 0.0 + -0.0 is within 0 ULPs of 0.0 ([0.00000000000000000, 0.00000000000000000]) - - - NAN, !WithinULP(NAN, 123) - - - nanf not is within 123 ULPs of nanf - - - +
@@ -3635,7 +3619,7 @@ Nor would this 1., WithinAbs(1., 0.5) || WithinULP(2., 1) - 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ) + 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ([1.99999999999999978, 2.00000000000000044]) ) @@ -3643,18 +3627,10 @@ Nor would this 1., WithinAbs(2., 0.5) || WithinULP(1., 0) - 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ) + 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ([1.00000000000000000, 1.00000000000000000]) ) - - - NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) - - - nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) - - - +
@@ -3735,14 +3711,6 @@ Nor would this 0.0f is within 0.0 of -0.0 - - - NAN, !WithinAbs(NAN, 0) - - - nanf not is within 0.0 of nan - - 11.f, !WithinAbs(10.f, 0.5f) @@ -3775,7 +3743,7 @@ Nor would this -10.0f is within 0.5 of -9.6000003815 - +
@@ -3783,7 +3751,7 @@ Nor would this 1.f, WithinULP(1.f, 0) - 1.0f is within 0 ULPs of 1.0f + 1.0f is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) @@ -3791,7 +3759,7 @@ Nor would this nextafter(1.f, 2.f), WithinULP(1.f, 1) - 1.0f is within 1 ULPs of 1.0f + 1.0f is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) @@ -3799,7 +3767,7 @@ Nor would this nextafter(1.f, 0.f), WithinULP(1.f, 1) - 1.0f is within 1 ULPs of 1.0f + 1.0f is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) @@ -3807,7 +3775,7 @@ Nor would this nextafter(1.f, 2.f), !WithinULP(1.f, 0) - 1.0f not is within 0 ULPs of 1.0f + 1.0f not is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) @@ -3815,7 +3783,7 @@ Nor would this 1.f, WithinULP(1.f, 0) - 1.0f is within 0 ULPs of 1.0f + 1.0f is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) @@ -3823,18 +3791,10 @@ Nor would this -0.f, WithinULP(0.f, 0) - -0.0f is within 0 ULPs of 0.0f + -0.0f is within 0 ULPs of 0.0f ([0.00000000000000000, 0.00000000000000000]) - - - NAN, !WithinULP(NAN, 123) - - - nanf not is within 123 ULPs of nanf - - - +
@@ -3842,7 +3802,7 @@ Nor would this 1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1) - 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ) + 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ([0.99999994039535522, 1.00000011920928955]) ) @@ -3850,18 +3810,10 @@ Nor would this 1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0) - 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ) + 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ([1.00000000000000000, 1.00000000000000000]) ) - - - NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) - - - nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) - - - +
@@ -14674,7 +14626,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/UsageTests/Matchers.tests.cpp b/projects/SelfTest/UsageTests/Matchers.tests.cpp index d741e57c..6f9c3cb4 100644 --- a/projects/SelfTest/UsageTests/Matchers.tests.cpp +++ b/projects/SelfTest/UsageTests/Matchers.tests.cpp @@ -347,7 +347,6 @@ namespace { namespace MatchersTests { REQUIRE_THAT(0.f, !WithinAbs(1.f, 0.99f)); REQUIRE_THAT(0.f, WithinAbs(-0.f, 0)); - REQUIRE_THAT(NAN, !WithinAbs(NAN, 0)); REQUIRE_THAT(11.f, !WithinAbs(10.f, 0.5f)); REQUIRE_THAT(10.f, !WithinAbs(11.f, 0.5f)); @@ -363,14 +362,10 @@ namespace { namespace MatchersTests { REQUIRE_THAT(1.f, WithinULP(1.f, 0)); REQUIRE_THAT(-0.f, WithinULP(0.f, 0)); - - REQUIRE_THAT(NAN, !WithinULP(NAN, 123)); } SECTION("Composed") { REQUIRE_THAT(1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1)); REQUIRE_THAT(1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0)); - - REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123))); } SECTION("Constructor validation") { REQUIRE_NOTHROW(WithinAbs(1.f, 0.f)); @@ -389,8 +384,6 @@ namespace { namespace MatchersTests { REQUIRE_THAT(0., !WithinAbs(1., 0.99)); REQUIRE_THAT(0., !WithinAbs(1., 0.99)); - REQUIRE_THAT(NAN, !WithinAbs(NAN, 0)); - REQUIRE_THAT(11., !WithinAbs(10., 0.5)); REQUIRE_THAT(10., !WithinAbs(11., 0.5)); REQUIRE_THAT(-10., WithinAbs(-10., 0.5)); @@ -405,14 +398,10 @@ namespace { namespace MatchersTests { REQUIRE_THAT(1., WithinULP(1., 0)); REQUIRE_THAT(-0., WithinULP(0., 0)); - - REQUIRE_THAT(NAN, !WithinULP(NAN, 123)); } SECTION("Composed") { REQUIRE_THAT(1., WithinAbs(1., 0.5) || WithinULP(2., 1)); REQUIRE_THAT(1., WithinAbs(2., 0.5) || WithinULP(1., 0)); - - REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123))); } SECTION("Constructor validation") { REQUIRE_NOTHROW(WithinAbs(1., 0.)); @@ -423,6 +412,12 @@ namespace { namespace MatchersTests { } } + TEST_CASE("Floating point matchers that are problematic in approvals", "[approvals][matchers][floating-point]") { + REQUIRE_THAT(NAN, !WithinAbs(NAN, 0)); + REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123))); + REQUIRE_THAT(NAN, !WithinULP(NAN, 123)); + } + TEST_CASE("Arbitrary predicate matcher", "[matchers][generic]") { SECTION("Function pointer") { REQUIRE_THAT(1, Predicate(alwaysTrue, "always true"));