diff --git a/include/internal/catch_matchers_floating.cpp b/include/internal/catch_matchers_floating.cpp index fb5f8d6a..3d2e342a 100644 --- a/include/internal/catch_matchers_floating.cpp +++ b/include/internal/catch_matchers_floating.cpp @@ -6,8 +6,9 @@ */ #include "catch_matchers_floating.h" +#include "catch_tostring.h" -#include +#include #include #include #include @@ -87,7 +88,7 @@ namespace Floating { } std::string WithinAbsMatcher::describe() const { - return "is within " + std::to_string(m_margin) + " of " + std::to_string(m_target); + return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target); } @@ -110,7 +111,7 @@ namespace Floating { } std::string WithinUlpsMatcher::describe() const { - return "is within " + std::to_string(m_ulps) + " ULPs of " + std::to_string(m_target) + ((m_type == FloatingPointKind::Float)? "f" : ""); + return "is within " + std::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : ""); } }// namespace Floating diff --git a/include/internal/catch_tostring.cpp b/include/internal/catch_tostring.cpp index dc6f3af5..700315de 100644 --- a/include/internal/catch_tostring.cpp +++ b/include/internal/catch_tostring.cpp @@ -17,6 +17,7 @@ #include "catch_interfaces_config.h" #include "catch_context.h" +#include #include namespace Catch { @@ -63,6 +64,10 @@ namespace Detail { template std::string fpToString( T value, int precision ) { + if (std::isnan(value)) { + return "nan"; + } + ReusableStringStream rss; rss << std::setprecision( precision ) << std::fixed diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 9ba153b6..2f2f0d51 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -1740,31 +1740,31 @@ MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1., WithinAbs(1., 0) ) with expansion: - 1.0 is within 0.000000 of 1.000000 + 1.0 is within 0.0 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 0., WithinAbs(1., 1) ) with expansion: - 0.0 is within 1.000000 of 1.000000 + 0.0 is within 1.0 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 0., !WithinAbs(1., 0.99) ) with expansion: - 0.0 not is within 0.990000 of 1.000000 + 0.0 not is within 0.99 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 0., !WithinAbs(1., 0.99) ) with expansion: - 0.0 not is within 0.990000 of 1.000000 + 0.0 not is within 0.99 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( NAN, !WithinAbs(NAN, 0) ) with expansion: - nanf not is within 0.000000 of nan + nanf not is within 0.0 of nan ------------------------------------------------------------------------------- Floating point matchers: double @@ -1777,37 +1777,37 @@ MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1., WithinULP(1., 0) ) with expansion: - 1.0 is within 0 ULPs of 1.000000 + 1.0 is within 0 ULPs of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( std::nextafter(1., 2.), WithinULP(1., 1) ) with expansion: - 1.0 is within 1 ULPs of 1.000000 + 1.0 is within 1 ULPs of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( std::nextafter(1., 0.), WithinULP(1., 1) ) with expansion: - 1.0 is within 1 ULPs of 1.000000 + 1.0 is within 1 ULPs of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( std::nextafter(1., 2.), !WithinULP(1., 0) ) with expansion: - 1.0 not is within 0 ULPs of 1.000000 + 1.0 not is within 0 ULPs of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1., WithinULP(1., 0) ) with expansion: - 1.0 is within 0 ULPs of 1.000000 + 1.0 is within 0 ULPs of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( -0., WithinULP(0., 0) ) with expansion: - -0.0 is within 0 ULPs of 0.000000 + -0.0 is within 0 ULPs of 0.0 MatchersTests.cpp:: PASSED: @@ -1826,19 +1826,19 @@ MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1., WithinAbs(1., 0.5) || WithinULP(2., 1) ) with expansion: - 1.0 ( is within 0.500000 of 1.000000 or is within 1 ULPs of 2.000000 ) + 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ) MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1., WithinAbs(2., 0.5) || WithinULP(1., 0) ) with expansion: - 1.0 ( is within 0.500000 of 2.000000 or is within 0 ULPs of 1.000000 ) + 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ) MatchersTests.cpp:: PASSED: REQUIRE_THAT( NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) ) with expansion: - nanf not ( is within 100.000000 of nan or is within 123 ULPs of nanf ) + nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) ------------------------------------------------------------------------------- Floating point matchers: float @@ -1851,37 +1851,37 @@ MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinAbs(1.f, 0) ) with expansion: - 1.0f is within 0.000000 of 1.000000 + 1.0f is within 0.0 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 0.f, WithinAbs(1.f, 1) ) with expansion: - 0.0f is within 1.000000 of 1.000000 + 0.0f is within 1.0 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 0.f, !WithinAbs(1.f, 0.99f) ) with expansion: - 0.0f not is within 0.990000 of 1.000000 + 0.0f not is within 0.9900000095 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 0.f, !WithinAbs(1.f, 0.99f) ) with expansion: - 0.0f not is within 0.990000 of 1.000000 + 0.0f not is within 0.9900000095 of 1.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( 0.f, WithinAbs(-0.f, 0) ) with expansion: - 0.0f is within 0.000000 of -0.000000 + 0.0f is within 0.0 of -0.0 MatchersTests.cpp:: PASSED: REQUIRE_THAT( NAN, !WithinAbs(NAN, 0) ) with expansion: - nanf not is within 0.000000 of nan + nanf not is within 0.0 of nan ------------------------------------------------------------------------------- Floating point matchers: float @@ -1894,37 +1894,37 @@ MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinULP(1.f, 0) ) with expansion: - 1.0f is within 0 ULPs of 1.000000f + 1.0f is within 0 ULPs of 1.0f MatchersTests.cpp:: PASSED: REQUIRE_THAT( std::nextafter(1.f, 2.f), WithinULP(1.f, 1) ) with expansion: - 1.0f is within 1 ULPs of 1.000000f + 1.0f is within 1 ULPs of 1.0f MatchersTests.cpp:: PASSED: REQUIRE_THAT( std::nextafter(1.f, 0.f), WithinULP(1.f, 1) ) with expansion: - 1.0f is within 1 ULPs of 1.000000f + 1.0f is within 1 ULPs of 1.0f MatchersTests.cpp:: PASSED: REQUIRE_THAT( std::nextafter(1.f, 2.f), !WithinULP(1.f, 0) ) with expansion: - 1.0f not is within 0 ULPs of 1.000000f + 1.0f not is within 0 ULPs of 1.0f MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinULP(1.f, 0) ) with expansion: - 1.0f is within 0 ULPs of 1.000000f + 1.0f is within 0 ULPs of 1.0f MatchersTests.cpp:: PASSED: REQUIRE_THAT( -0.f, WithinULP(0.f, 0) ) with expansion: - -0.0f is within 0 ULPs of 0.000000f + -0.0f is within 0 ULPs of 0.0f MatchersTests.cpp:: PASSED: @@ -1943,19 +1943,19 @@ MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1) ) with expansion: - 1.0f ( is within 0.500000 of 1.000000 or is within 1 ULPs of 1.000000f ) + 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ) MatchersTests.cpp:: PASSED: REQUIRE_THAT( 1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0) ) with expansion: - 1.0f ( is within 0.500000 of 2.000000 or is within 0 ULPs of 1.000000f ) + 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ) MatchersTests.cpp:: PASSED: REQUIRE_THAT( NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) ) with expansion: - nanf not ( is within 100.000000 of nan or is within 123 ULPs of nanf ) + nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) ------------------------------------------------------------------------------- Greater-than inequalities with different epsilons diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 89531ae0..b29a6962 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -1968,7 +1968,7 @@ 1., WithinAbs(1., 0) - 1.0 is within 0.000000 of 1.000000 + 1.0 is within 0.0 of 1.0 @@ -1976,7 +1976,7 @@ 0., WithinAbs(1., 1) - 0.0 is within 1.000000 of 1.000000 + 0.0 is within 1.0 of 1.0 @@ -1984,7 +1984,7 @@ 0., !WithinAbs(1., 0.99) - 0.0 not is within 0.990000 of 1.000000 + 0.0 not is within 0.99 of 1.0 @@ -1992,7 +1992,7 @@ 0., !WithinAbs(1., 0.99) - 0.0 not is within 0.990000 of 1.000000 + 0.0 not is within 0.99 of 1.0 @@ -2000,7 +2000,7 @@ NAN, !WithinAbs(NAN, 0) - nanf not is within 0.000000 of nan + nanf not is within 0.0 of nan @@ -2011,7 +2011,7 @@ 1., WithinULP(1., 0) - 1.0 is within 0 ULPs of 1.000000 + 1.0 is within 0 ULPs of 1.0 @@ -2019,7 +2019,7 @@ std::nextafter(1., 2.), WithinULP(1., 1) - 1.0 is within 1 ULPs of 1.000000 + 1.0 is within 1 ULPs of 1.0 @@ -2027,7 +2027,7 @@ std::nextafter(1., 0.), WithinULP(1., 1) - 1.0 is within 1 ULPs of 1.000000 + 1.0 is within 1 ULPs of 1.0 @@ -2035,7 +2035,7 @@ std::nextafter(1., 2.), !WithinULP(1., 0) - 1.0 not is within 0 ULPs of 1.000000 + 1.0 not is within 0 ULPs of 1.0 @@ -2043,7 +2043,7 @@ 1., WithinULP(1., 0) - 1.0 is within 0 ULPs of 1.000000 + 1.0 is within 0 ULPs of 1.0 @@ -2051,7 +2051,7 @@ -0., WithinULP(0., 0) - -0.0 is within 0 ULPs of 0.000000 + -0.0 is within 0 ULPs of 0.0 @@ -2070,7 +2070,7 @@ 1., WithinAbs(1., 0.5) || WithinULP(2., 1) - 1.0 ( is within 0.500000 of 1.000000 or is within 1 ULPs of 2.000000 ) + 1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 ) @@ -2078,7 +2078,7 @@ 1., WithinAbs(2., 0.5) || WithinULP(1., 0) - 1.0 ( is within 0.500000 of 2.000000 or is within 0 ULPs of 1.000000 ) + 1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 ) @@ -2086,7 +2086,7 @@ NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) - nanf not ( is within 100.000000 of nan or is within 123 ULPs of nanf ) + nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) @@ -2100,7 +2100,7 @@ 1.f, WithinAbs(1.f, 0) - 1.0f is within 0.000000 of 1.000000 + 1.0f is within 0.0 of 1.0 @@ -2108,7 +2108,7 @@ 0.f, WithinAbs(1.f, 1) - 0.0f is within 1.000000 of 1.000000 + 0.0f is within 1.0 of 1.0 @@ -2116,7 +2116,7 @@ 0.f, !WithinAbs(1.f, 0.99f) - 0.0f not is within 0.990000 of 1.000000 + 0.0f not is within 0.9900000095 of 1.0 @@ -2124,7 +2124,7 @@ 0.f, !WithinAbs(1.f, 0.99f) - 0.0f not is within 0.990000 of 1.000000 + 0.0f not is within 0.9900000095 of 1.0 @@ -2132,7 +2132,7 @@ 0.f, WithinAbs(-0.f, 0) - 0.0f is within 0.000000 of -0.000000 + 0.0f is within 0.0 of -0.0 @@ -2140,7 +2140,7 @@ NAN, !WithinAbs(NAN, 0) - nanf not is within 0.000000 of nan + nanf not is within 0.0 of nan @@ -2151,7 +2151,7 @@ 1.f, WithinULP(1.f, 0) - 1.0f is within 0 ULPs of 1.000000f + 1.0f is within 0 ULPs of 1.0f @@ -2159,7 +2159,7 @@ std::nextafter(1.f, 2.f), WithinULP(1.f, 1) - 1.0f is within 1 ULPs of 1.000000f + 1.0f is within 1 ULPs of 1.0f @@ -2167,7 +2167,7 @@ std::nextafter(1.f, 0.f), WithinULP(1.f, 1) - 1.0f is within 1 ULPs of 1.000000f + 1.0f is within 1 ULPs of 1.0f @@ -2175,7 +2175,7 @@ std::nextafter(1.f, 2.f), !WithinULP(1.f, 0) - 1.0f not is within 0 ULPs of 1.000000f + 1.0f not is within 0 ULPs of 1.0f @@ -2183,7 +2183,7 @@ 1.f, WithinULP(1.f, 0) - 1.0f is within 0 ULPs of 1.000000f + 1.0f is within 0 ULPs of 1.0f @@ -2191,7 +2191,7 @@ -0.f, WithinULP(0.f, 0) - -0.0f is within 0 ULPs of 0.000000f + -0.0f is within 0 ULPs of 0.0f @@ -2210,7 +2210,7 @@ 1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1) - 1.0f ( is within 0.500000 of 1.000000 or is within 1 ULPs of 1.000000f ) + 1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f ) @@ -2218,7 +2218,7 @@ 1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0) - 1.0f ( is within 0.500000 of 2.000000 or is within 0 ULPs of 1.000000f ) + 1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f ) @@ -2226,7 +2226,7 @@ NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) - nanf not ( is within 100.000000 of nan or is within 123 ULPs of nanf ) + nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf ) diff --git a/scripts/approvalTests.py b/scripts/approvalTests.py index 09fff7c7..92a40a0e 100755 --- a/scripts/approvalTests.py +++ b/scripts/approvalTests.py @@ -57,7 +57,9 @@ nanParser = re.compile(r''' | \(\(float\)\(INFINITY\ \*\ 0\.0F\)\) # Yet another MSVC NAN macro | - \(__builtin_nanf\ \(""\)\) # Linux (ubuntu) NAN macro + \(__builtin_nanf\ \(""\)\) # Linux (ubuntu) NAN macro + | + __builtin_nanf\("0x"\) # The weird content of the brackets is there because a different parser has already ran before this one ''', re.VERBOSE)