mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Add std::isnan
polyfill, fixing compilation under Embarcadero
Fixes #1438
This commit is contained in:
parent
a9d5b7193d
commit
c6a89f14c2
@ -157,6 +157,12 @@
|
|||||||
# define CATCH_INTERNAL_CONFIG_NO_WCHAR
|
# define CATCH_INTERNAL_CONFIG_NO_WCHAR
|
||||||
#endif // __DJGPP__
|
#endif // __DJGPP__
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Embarcadero C++Build
|
||||||
|
#if defined(__BORLANDC__)
|
||||||
|
#define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Use of __COUNTER__ is suppressed during code analysis in
|
// Use of __COUNTER__ is suppressed during code analysis in
|
||||||
@ -238,6 +244,10 @@
|
|||||||
# define CATCH_CONFIG_DISABLE_EXCEPTIONS
|
# define CATCH_CONFIG_DISABLE_EXCEPTIONS
|
||||||
#endif
|
#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)
|
#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
|
||||||
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
|
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
|
||||||
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
|
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "catch_matchers_floating.h"
|
#include "catch_matchers_floating.h"
|
||||||
#include "catch_enforce.h"
|
#include "catch_enforce.h"
|
||||||
|
#include "catch_polyfills.hpp"
|
||||||
#include "catch_to_string.hpp"
|
#include "catch_to_string.hpp"
|
||||||
#include "catch_tostring.h"
|
#include "catch_tostring.h"
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ template <typename FP>
|
|||||||
bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) {
|
bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) {
|
||||||
// Comparison with NaN should always be false.
|
// Comparison with NaN should always be false.
|
||||||
// This way we can rule it out before getting into the ugly details
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
include/internal/catch_polyfills.cpp
Normal file
31
include/internal/catch_polyfills.cpp
Normal file
@ -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 <cmath>
|
||||||
|
|
||||||
|
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
|
15
include/internal/catch_polyfills.hpp
Normal file
15
include/internal/catch_polyfills.hpp
Normal file
@ -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
|
@ -20,6 +20,7 @@
|
|||||||
#include "catch_tostring.h"
|
#include "catch_tostring.h"
|
||||||
#include "catch_interfaces_config.h"
|
#include "catch_interfaces_config.h"
|
||||||
#include "catch_context.h"
|
#include "catch_context.h"
|
||||||
|
#include "catch_polyfills.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -68,7 +69,7 @@ namespace Detail {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string fpToString( T value, int precision ) {
|
std::string fpToString( T value, int precision ) {
|
||||||
if (std::isnan(value)) {
|
if (Catch::isnan(value)) {
|
||||||
return "nan";
|
return "nan";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ set(INTERNAL_HEADERS
|
|||||||
${HEADER_DIR}/internal/catch_option.hpp
|
${HEADER_DIR}/internal/catch_option.hpp
|
||||||
${HEADER_DIR}/internal/catch_output_redirect.h
|
${HEADER_DIR}/internal/catch_output_redirect.h
|
||||||
${HEADER_DIR}/internal/catch_platform.h
|
${HEADER_DIR}/internal/catch_platform.h
|
||||||
|
${HEADER_DIR}/internal/catch_polyfills.hpp
|
||||||
${HEADER_DIR}/internal/catch_preprocessor.hpp
|
${HEADER_DIR}/internal/catch_preprocessor.hpp
|
||||||
${HEADER_DIR}/internal/catch_random_number_generator.h
|
${HEADER_DIR}/internal/catch_random_number_generator.h
|
||||||
${HEADER_DIR}/internal/catch_reenable_warnings.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_output_redirect.cpp
|
||||||
${HEADER_DIR}/internal/catch_registry_hub.cpp
|
${HEADER_DIR}/internal/catch_registry_hub.cpp
|
||||||
${HEADER_DIR}/internal/catch_interfaces_reporter.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_random_number_generator.cpp
|
||||||
${HEADER_DIR}/internal/catch_reporter_registry.cpp
|
${HEADER_DIR}/internal/catch_reporter_registry.cpp
|
||||||
${HEADER_DIR}/internal/catch_result_type.cpp
|
${HEADER_DIR}/internal/catch_result_type.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user