From b44c70b3f49883a67d3f819d7640e58333860a2e Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 30 Oct 2016 22:49:38 +0000 Subject: [PATCH] Simplify isnan detection with C++11 library. --- CMakeLists.txt | 11 +++++------ simgear/math/SGMisc.hxx | 10 ---------- simgear/simgear_config_cmake.h.in | 2 +- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33c93aab..b9b3c450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 - int main() { return isnan(0.0);} " - HAVE_ISNAN) - -check_cxx_source_compiles( - "#include + "#include 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") diff --git a/simgear/math/SGMisc.hxx b/simgear/math/SGMisc.hxx index 79030536..47e89f75 100644 --- a/simgear/math/SGMisc.hxx +++ b/simgear/math/SGMisc.hxx @@ -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 } }; diff --git a/simgear/simgear_config_cmake.h.in b/simgear/simgear_config_cmake.h.in index c9804e7c..0490b3f8 100644 --- a/simgear/simgear_config_cmake.h.in +++ b/simgear/simgear_config_cmake.h.in @@ -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