Simplify isnan detection with C++11 library.

This commit is contained in:
James Turner
2016-10-30 22:49:38 +00:00
parent e4cddb100e
commit b44c70b3f4
3 changed files with 6 additions and 17 deletions

View File

@@ -328,15 +328,14 @@ SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on wi
# isnan might not be real symbol, so can't check using function_exists
check_cxx_source_compiles(
"#include <cmath>
int main() { return isnan(0.0);} "
HAVE_ISNAN)
check_cxx_source_compiles(
"#include <cmath>
"#include <cstdlib>
int main() { return std::isnan(0.0);} "
HAVE_STD_ISNAN)
if (NOT ${HAVE_STD_ISNAN})
message(FATAL_ERROR "Your compiler lacks C++11 std::isnan, please update it")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(WARNING_FLAGS_CXX "-Wall")
set(WARNING_FLAGS_C "-Wall")

View File

@@ -153,17 +153,7 @@ public:
/// Use with care: allways code that you do not need to use that!
static bool isNaN(const T& v)
{
#ifdef HAVE_STD_ISNAN
return std::isnan(v);
#elif defined HAVE_ISNAN
return (isnan(v) != 0);
#else
// Use that every compare involving a NaN returns false
// But be careful, some usual compiler switches like for example
// -fast-math from gcc might optimize that expression to v != v which
// behaves exactly like the opposite ...
return !(v == v);
#endif
}
};

View File

@@ -9,7 +9,7 @@
#cmakedefine HAVE_FTIME
#cmakedefine HAVE_RINT
#cmakedefine HAVE_TIMEGM
#cmakedefine HAVE_ISNAN
#cmakedefine HAVE_STD_ISNAN
#cmakedefine HAVE_WINDOWS_H
#cmakedefine HAVE_MKDTEMP