diff --git a/include/internal/catch_compiler_capabilities.h b/include/internal/catch_compiler_capabilities.h index 41627570..cf3a4424 100644 --- a/include/internal/catch_compiler_capabilities.h +++ b/include/internal/catch_compiler_capabilities.h @@ -157,6 +157,12 @@ # define CATCH_INTERNAL_CONFIG_NO_WCHAR #endif // __DJGPP__ +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN +#endif + //////////////////////////////////////////////////////////////////////////////// // Use of __COUNTER__ is suppressed during code analysis in @@ -238,6 +244,10 @@ # define CATCH_CONFIG_DISABLE_EXCEPTIONS #endif +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN +#endif + #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS diff --git a/include/internal/catch_matchers_floating.cpp b/include/internal/catch_matchers_floating.cpp index 31206986..9bc082ed 100644 --- a/include/internal/catch_matchers_floating.cpp +++ b/include/internal/catch_matchers_floating.cpp @@ -7,6 +7,7 @@ #include "catch_matchers_floating.h" #include "catch_enforce.h" +#include "catch_polyfills.hpp" #include "catch_to_string.hpp" #include "catch_tostring.h" @@ -57,7 +58,7 @@ template bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { // Comparison with NaN should always be false. // This way we can rule it out before getting into the ugly details - if (std::isnan(lhs) || std::isnan(rhs)) { + if (Catch::isnan(lhs) || Catch::isnan(rhs)) { return false; } diff --git a/include/internal/catch_polyfills.cpp b/include/internal/catch_polyfills.cpp new file mode 100644 index 00000000..68a2c827 --- /dev/null +++ b/include/internal/catch_polyfills.cpp @@ -0,0 +1,31 @@ +/* + * Created by Martin on 17/11/2017. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#include "catch_polyfills.hpp" + +#include + +namespace Catch { + +#if !defined(CATCH_CONFIG_POLYFILL_ISNAN) + bool isnan(float f) { + return std::isnan(f); + } + bool isnan(double d) { + return std::isnan(d); + } +#else + // For now we only use this for embarcadero + bool isnan(float f) { + return std::_isnan(f); + } + bool isnan(double d) { + return std::_isnan(d); + } +#endif + +} // end namespace Catch diff --git a/include/internal/catch_polyfills.hpp b/include/internal/catch_polyfills.hpp new file mode 100644 index 00000000..ba4189ef --- /dev/null +++ b/include/internal/catch_polyfills.hpp @@ -0,0 +1,15 @@ +/* + * Created by Martin on 17/11/2017. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_CATCH_POLYFILLS_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_POLYFILLS_HPP_INCLUDED + +namespace Catch { + bool isnan(float f); + bool isnan(double d); +} + +#endif // TWOBLUECUBES_CATCH_POLYFILLS_HPP_INCLUDED diff --git a/include/internal/catch_tostring.cpp b/include/internal/catch_tostring.cpp index 8cbabbf2..b857d3fb 100644 --- a/include/internal/catch_tostring.cpp +++ b/include/internal/catch_tostring.cpp @@ -20,6 +20,7 @@ #include "catch_tostring.h" #include "catch_interfaces_config.h" #include "catch_context.h" +#include "catch_polyfills.hpp" #include #include @@ -68,7 +69,7 @@ namespace Detail { template std::string fpToString( T value, int precision ) { - if (std::isnan(value)) { + if (Catch::isnan(value)) { return "nan"; } diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index aa827673..5dc945e8 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -123,6 +123,7 @@ set(INTERNAL_HEADERS ${HEADER_DIR}/internal/catch_option.hpp ${HEADER_DIR}/internal/catch_output_redirect.h ${HEADER_DIR}/internal/catch_platform.h + ${HEADER_DIR}/internal/catch_polyfills.hpp ${HEADER_DIR}/internal/catch_preprocessor.hpp ${HEADER_DIR}/internal/catch_random_number_generator.h ${HEADER_DIR}/internal/catch_reenable_warnings.h @@ -198,6 +199,7 @@ set(IMPL_SOURCES ${HEADER_DIR}/internal/catch_output_redirect.cpp ${HEADER_DIR}/internal/catch_registry_hub.cpp ${HEADER_DIR}/internal/catch_interfaces_reporter.cpp + ${HEADER_DIR}/internal/catch_polyfills.cpp ${HEADER_DIR}/internal/catch_random_number_generator.cpp ${HEADER_DIR}/internal/catch_reporter_registry.cpp ${HEADER_DIR}/internal/catch_result_type.cpp