mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Add std::isnan polyfill, fixing compilation under Embarcadero
				
					
				
			Fixes #1438
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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 <typename FP> | ||||
| 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; | ||||
|     } | ||||
|  | ||||
|   | ||||
							
								
								
									
										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_interfaces_config.h" | ||||
| #include "catch_context.h" | ||||
| #include "catch_polyfills.hpp" | ||||
|  | ||||
| #include <cmath> | ||||
| #include <iomanip> | ||||
| @@ -68,7 +69,7 @@ namespace Detail { | ||||
|  | ||||
| template<typename T> | ||||
| std::string fpToString( T value, int precision ) { | ||||
|     if (std::isnan(value)) { | ||||
|     if (Catch::isnan(value)) { | ||||
|         return "nan"; | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský