summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-07-19 07:08:03 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-07-19 07:38:37 +0200
commit0773f40c072bdf117fff9e7179849b65737e7491 (patch)
tree534d764580eb312ada0dea038a1632fac97c5e2a /opentrack-compat
parent9296ed95961b846a13477581e2947b8be611b154 (diff)
move nan check to compat
Diffstat (limited to 'opentrack-compat')
-rw-r--r--opentrack-compat/CMakeLists.txt4
-rw-r--r--opentrack-compat/nan.cpp16
-rw-r--r--opentrack-compat/nan.hpp11
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