diff options
Diffstat (limited to 'opentrack-compat')
-rw-r--r-- | opentrack-compat/CMakeLists.txt | 4 | ||||
-rw-r--r-- | opentrack-compat/nan.cpp | 16 | ||||
-rw-r--r-- | opentrack-compat/nan.hpp | 11 |
3 files changed, 31 insertions, 0 deletions
diff --git a/opentrack-compat/CMakeLists.txt b/opentrack-compat/CMakeLists.txt index 6f745701..2bbb496c 100644 --- a/opentrack-compat/CMakeLists.txt +++ b/opentrack-compat/CMakeLists.txt @@ -2,3 +2,7 @@ opentrack_boilerplate(opentrack-compat NO-COMPAT BIN) if(NOT WIN32 AND NOT APPLE) target_link_libraries(opentrack-compat rt) endif() +if(CMAKE_COMPILER_IS_GNUCXX) + set_source_files_properties(nan.cpp PROPERTIES + COMPILE_FLAGS "-fno-fast-math -fno-finite-math-only -O0") +endif() diff --git a/opentrack-compat/nan.cpp b/opentrack-compat/nan.cpp new file mode 100644 index 00000000..6c4b1f6d --- /dev/null +++ b/opentrack-compat/nan.cpp @@ -0,0 +1,16 @@ +#include <cmath> + +#if defined(__GNUC__) +extern "C" bool __attribute__ ((noinline)) nanp(double value) +#elif defined(_WIN32) +extern "C" __declspec(noinline) bool nanp(double value) +#else +extern "C" bool nanp(double value) +#endif +{ + using std::isnan; + using std::isinf; + + const volatile double x = value; + return isnan(x) || isinf(x); +} diff --git a/opentrack-compat/nan.hpp b/opentrack-compat/nan.hpp new file mode 100644 index 00000000..f9e5cc1e --- /dev/null +++ b/opentrack-compat/nan.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "export.hpp" + +#if defined(__GNUC__) +extern "C" OPENTRACK_COMPAT_EXPORT bool __attribute__ ((noinline)) nanp(double value); +#elif defined(_WIN32) +extern "C" __declspec(noinline) OPENTRACK_COMPAT_EXPORT bool nanp(double value); +#else +extern "C" OPENTRACK_COMPAT_EXPORT bool nanp(double value); +#endif |