Simplify isnan detection with C++11 library.
This commit is contained in:
+5
-6
@@ -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
|
# isnan might not be real symbol, so can't check using function_exists
|
||||||
check_cxx_source_compiles(
|
check_cxx_source_compiles(
|
||||||
"#include <cmath>
|
"#include <cstdlib>
|
||||||
int main() { return isnan(0.0);} "
|
|
||||||
HAVE_ISNAN)
|
|
||||||
|
|
||||||
check_cxx_source_compiles(
|
|
||||||
"#include <cmath>
|
|
||||||
int main() { return std::isnan(0.0);} "
|
int main() { return std::isnan(0.0);} "
|
||||||
HAVE_STD_ISNAN)
|
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)
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
set(WARNING_FLAGS_CXX "-Wall")
|
set(WARNING_FLAGS_CXX "-Wall")
|
||||||
set(WARNING_FLAGS_C "-Wall")
|
set(WARNING_FLAGS_C "-Wall")
|
||||||
|
|||||||
@@ -153,17 +153,7 @@ public:
|
|||||||
/// Use with care: allways code that you do not need to use that!
|
/// Use with care: allways code that you do not need to use that!
|
||||||
static bool isNaN(const T& v)
|
static bool isNaN(const T& v)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_STD_ISNAN
|
|
||||||
return std::isnan(v);
|
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
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#cmakedefine HAVE_FTIME
|
#cmakedefine HAVE_FTIME
|
||||||
#cmakedefine HAVE_RINT
|
#cmakedefine HAVE_RINT
|
||||||
#cmakedefine HAVE_TIMEGM
|
#cmakedefine HAVE_TIMEGM
|
||||||
#cmakedefine HAVE_ISNAN
|
|
||||||
#cmakedefine HAVE_STD_ISNAN
|
#cmakedefine HAVE_STD_ISNAN
|
||||||
#cmakedefine HAVE_WINDOWS_H
|
#cmakedefine HAVE_WINDOWS_H
|
||||||
#cmakedefine HAVE_MKDTEMP
|
#cmakedefine HAVE_MKDTEMP
|
||||||
|
|||||||
Reference in New Issue
Block a user