Move nextafter polyfill to polyfills.hpp

This commit is contained in:
Martin Hořeňovský 2023-11-18 16:17:49 +01:00
parent 9a1e73568c
commit bfd9f0f5a6
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
3 changed files with 13 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}