Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Move nextafter polyfill to polyfills.hpp

Commit
bfd9f0f5a67c0127b25ac82eb828f6ab71aaae1e
Author
Martin Hořeňovský ·
Parents
9a1e73568c86

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_polyfills.cpp               |  8 ++++++++
 src/catch2/internal/catch_polyfills.hpp               |  5 +++++
 src/catch2/matchers/catch_matchers_floating_point.cpp | 15 ---------------
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/catch2/internal/catch_polyfills.cpp b/src/catch2/internal/catch_polyfills.cpp
index 96efad5d..776c2243 100644
--- a/src/catch2/internal/catch_polyfills.cpp
+++ b/src/catch2/internal/catch_polyfills.cpp
@@ -31,4 +31,12 @@ namespace Catch {
     }
 #endif
 
+#if !defined( CATCH_CONFIG_GLOBAL_NEXTAFTER )
+    float nextafter( float x, float y ) { return std::nextafter( x, y ); }
+    double nextafter( double x, double y ) { return std::nextafter( x, y ); }
+#else
+    float nextafter( float x, float y ) { return ::nextafterf( x, y ); }
+    double nextafter( double x, double y ) { return ::nextafter( x, y ); }
+#endif
+
 } // end namespace Catch
diff --git a/src/catch2/internal/catch_polyfills.hpp b/src/catch2/internal/catch_polyfills.hpp
index 23a9332b..4503f8f2 100644
--- a/src/catch2/internal/catch_polyfills.hpp
+++ b/src/catch2/internal/catch_polyfills.hpp
@@ -9,8 +9,13 @@
 #define CATCH_POLYFILLS_HPP_INCLUDED
 
 namespace Catch {
+
     bool isnan(float f);
     bool isnan(double d);
+
+    float nextafter(float x, float y);
+    double nextafter(double x, double y);
+
 }
 
 #endif // CATCH_POLYFILLS_HPP_INCLUDED
diff --git a/src/catch2/matchers/catch_matchers_floating_point.cpp b/src/catch2/matchers/catch_matchers_floating_point.cpp
index 6e596466..206332ef 100644
--- a/src/catch2/matchers/catch_matchers_floating_point.cpp
+++ b/src/catch2/matchers/catch_matchers_floating_point.cpp
@@ -38,26 +38,11 @@ namespace {
         return ulpDist <= maxUlpDiff;
     }
 
-#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
-
-    float nextafter(float x, float y) {
-        return ::nextafterf(x, y);
-    }
-
-    double nextafter(double x, double y) {
-        return ::nextafter(x, y);
-    }
-
-#endif // ^^^ CATCH_CONFIG_GLOBAL_NEXTAFTER ^^^
 
 template <typename FP>
 FP step(FP start, FP direction, uint64_t steps) {
     for (uint64_t i = 0; i < steps; ++i) {
-#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
         start = Catch::nextafter(start, direction);
-#else
-        start = std::nextafter(start, direction);
-#endif
     }
     return start;
 }