From dcef445e694c6e2b65d7f1fd0462f4ceacdaff3c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 14 Jun 2016 11:43:06 +0200 Subject: api: add nan checking function --- opentrack/CMakeLists.txt | 3 +++ opentrack/nan.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 opentrack/nan.cpp (limited to 'opentrack') diff --git a/opentrack/CMakeLists.txt b/opentrack/CMakeLists.txt index 7763178d..dd90bda6 100644 --- a/opentrack/CMakeLists.txt +++ b/opentrack/CMakeLists.txt @@ -5,3 +5,6 @@ if(NOT WIN32) else() target_link_libraries(opentrack-api winmm) endif() +if(CMAKE_COMPILER_IS_GNUCXX) + set_source_files_properties(nan.cpp PROPERTIES COMPILE_FLAGS "-fno-fast-math -fno-finite-math-only -fno-fast-math -O2") +endif() diff --git a/opentrack/nan.cpp b/opentrack/nan.cpp new file mode 100644 index 00000000..2522ba38 --- /dev/null +++ b/opentrack/nan.cpp @@ -0,0 +1,16 @@ +#include + +#if defined(__GNUC__) +bool __attribute__ ((noinline)) nanp(double value) +#elif defined(_WIN32) +__declspec(noinline) bool nanp(double value) +#else +bool nanp(double value) +#endif +{ + using std::isnan; + using std::isinf; + + const volatile double x = value; + return isnan(x) || isinf(x); +} \ No newline at end of file -- cgit v1.2.3