summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-06-18 12:44:51 -0400
committerjsmall-nvidia <jsmall@nvidia.com>2020-06-18 12:44:51 -0400
commit48da3ed09c84cd53f24b1f3628402f0bbc92e540 (patch)
tree749ac0d932abf7f1e51472f4c00ee79c8b5f34c8
parentf9b5f18fb5306e3dc1f9bef8106f98b5f9cb468f (diff)
#include <cmath>
Use SLANG_PRELUDE_STD macro to prefix functions that may need to be specified in std:: namespace.
-rw-r--r--prelude/slang-cpp-prelude.h2
-rw-r--r--prelude/slang-cpp-scalar-intrinsics.h18
2 files changed, 13 insertions, 7 deletions
diff --git a/prelude/slang-cpp-prelude.h b/prelude/slang-cpp-prelude.h
index 2e680f824..4a07674d1 100644
--- a/prelude/slang-cpp-prelude.h
+++ b/prelude/slang-cpp-prelude.h
@@ -3,7 +3,7 @@
#include "../slang.h"
-#include <math.h>
+#include <cmath>
#include <assert.h>
#include <stdlib.h>
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h
index c7d654170..f6c35e393 100644
--- a/prelude/slang-cpp-scalar-intrinsics.h
+++ b/prelude/slang-cpp-scalar-intrinsics.h
@@ -8,6 +8,12 @@
# include <intrin.h>
#endif
+// Because the signiture of isnan, isfinite, and is isinf changed in C++, we use the macro
+// to use the version in the std namespace.
+// https://stackoverflow.com/questions/39130040/cmath-hides-isnan-in-math-h-in-c14-c11
+
+#define SLANG_PRELUDE_STD std::
+
#ifdef SLANG_PRELUDE_NAMESPACE
namespace SLANG_PRELUDE_NAMESPACE {
#endif
@@ -68,9 +74,9 @@ SLANG_FORCE_INLINE float F32_rsqrt(float f) { return 1.0f / F32_sqrt(f); }
SLANG_FORCE_INLINE float F32_sign(float f) { return ( f == 0.0f) ? f : (( f < 0.0f) ? -1.0f : 1.0f); }
SLANG_FORCE_INLINE float F32_frac(float f) { return f - F32_floor(f); }
-SLANG_FORCE_INLINE bool F32_isnan(float f) { return isnan(f); }
-SLANG_FORCE_INLINE bool F32_isfinite(float f) { return isfinite(f); }
-SLANG_FORCE_INLINE bool F32_isinf(float f) { return isinf(f); }
+SLANG_FORCE_INLINE bool F32_isnan(float f) { return SLANG_PRELUDE_STD isnan(f); }
+SLANG_FORCE_INLINE bool F32_isfinite(float f) { return SLANG_PRELUDE_STD isfinite(f); }
+SLANG_FORCE_INLINE bool F32_isinf(float f) { return SLANG_PRELUDE_STD isinf(f); }
// Binary
SLANG_FORCE_INLINE float F32_min(float a, float b) { return ::fminf(a, b); }
@@ -135,9 +141,9 @@ SLANG_FORCE_INLINE double F64_rsqrt(double f) { return 1.0 / F64_sqrt(f); }
SLANG_FORCE_INLINE double F64_sign(double f) { return (f == 0.0) ? f : ((f < 0.0) ? -1.0 : 1.0); }
SLANG_FORCE_INLINE double F64_frac(double f) { return f - F64_floor(f); }
-SLANG_FORCE_INLINE bool F64_isnan(double f) { return isnan(f); }
-SLANG_FORCE_INLINE bool F64_isfinite(double f) { return isfinite(f); }
-SLANG_FORCE_INLINE bool F64_isinf(double f) { return isinf(f); }
+SLANG_FORCE_INLINE bool F64_isnan(double f) { return SLANG_PRELUDE_STD isnan(f); }
+SLANG_FORCE_INLINE bool F64_isfinite(double f) { return SLANG_PRELUDE_STD isfinite(f); }
+SLANG_FORCE_INLINE bool F64_isinf(double f) { return SLANG_PRELUDE_STD isinf(f); }
// Binary
SLANG_FORCE_INLINE double F64_min(double a, double b) { return ::fmin(a, b); }