From c6efc4e0ba4b9acb8f99e6e976d4853bedc21db5 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Fri, 11 Dec 2020 14:34:31 -0800 Subject: Replace M_LOG2E and M_LN2 with custom macros. For these to exist we would need to define `_USE_MATH_DEFINES` before `cmath` or `math.h` is first included. However, we don't control the include order for projects outside Eigen, so even defining the macro in `Eigen/Core` does not fix the issue for projects that end up including `` before Eigen does (explicitly or transitively). To fix this, we define `EIGEN_LOG2E` and `EIGEN_LN2` ourselves. --- Eigen/src/Core/arch/Default/BFloat16.h | 2 +- Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h | 8 ++++---- Eigen/src/Core/arch/Default/Half.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'Eigen/src/Core/arch/Default') diff --git a/Eigen/src/Core/arch/Default/BFloat16.h b/Eigen/src/Core/arch/Default/BFloat16.h index 616dcf667..72a489b0b 100644 --- a/Eigen/src/Core/arch/Default/BFloat16.h +++ b/Eigen/src/Core/arch/Default/BFloat16.h @@ -513,7 +513,7 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log10(const bfloat16& a) { return bfloat16(::log10f(float(a))); } EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log2(const bfloat16& a) { - return bfloat16(static_cast(M_LOG2E) * ::logf(float(a))); + return bfloat16(static_cast(EIGEN_LOG2E) * ::logf(float(a))); } EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sqrt(const bfloat16& a) { return bfloat16(::sqrtf(float(a))); diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 45cc780f1..34e2cb1e7 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -132,10 +132,10 @@ Packet plog_impl_float(const Packet _x) // Add the logarithm of the exponent back to the result of the interpolation. if (base2) { - const Packet cst_log2e = pset1(static_cast(M_LOG2E)); + const Packet cst_log2e = pset1(static_cast(EIGEN_LOG2E)); x = pmadd(x, cst_log2e, e); } else { - const Packet cst_ln2 = pset1(static_cast(M_LN2)); + const Packet cst_ln2 = pset1(static_cast(EIGEN_LN2)); x = pmadd(e, cst_ln2, x); } @@ -253,10 +253,10 @@ Packet plog_impl_double(const Packet _x) // Add the logarithm of the exponent back to the result of the interpolation. if (base2) { - const Packet cst_log2e = pset1(M_LOG2E); + const Packet cst_log2e = pset1(EIGEN_LOG2E); x = pmadd(x, cst_log2e, e); } else { - const Packet cst_ln2 = pset1(M_LN2); + const Packet cst_ln2 = pset1(EIGEN_LN2); x = pmadd(e, cst_ln2, x); } diff --git a/Eigen/src/Core/arch/Default/Half.h b/Eigen/src/Core/arch/Default/Half.h index 204076e25..54fd86aa7 100644 --- a/Eigen/src/Core/arch/Default/Half.h +++ b/Eigen/src/Core/arch/Default/Half.h @@ -623,7 +623,7 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(const half& a) { return half(::log10f(float(a))); } EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log2(const half& a) { - return half(static_cast(M_LOG2E) * ::logf(float(a))); + return half(static_cast(EIGEN_LOG2E) * ::logf(float(a))); } EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(const half& a) { -- cgit v1.2.3