mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
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 `<cmath>` before Eigen does (explicitly or transitively). To fix this, we define `EIGEN_LOG2E` and `EIGEN_LN2` ourselves.
This commit is contained in:
@@ -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<float>(M_LOG2E) * ::logf(float(a)));
|
||||
return bfloat16(static_cast<float>(EIGEN_LOG2E) * ::logf(float(a)));
|
||||
}
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sqrt(const bfloat16& a) {
|
||||
return bfloat16(::sqrtf(float(a)));
|
||||
|
||||
@@ -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<Packet>(static_cast<float>(M_LOG2E));
|
||||
const Packet cst_log2e = pset1<Packet>(static_cast<float>(EIGEN_LOG2E));
|
||||
x = pmadd(x, cst_log2e, e);
|
||||
} else {
|
||||
const Packet cst_ln2 = pset1<Packet>(static_cast<float>(M_LN2));
|
||||
const Packet cst_ln2 = pset1<Packet>(static_cast<float>(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<Packet>(M_LOG2E);
|
||||
const Packet cst_log2e = pset1<Packet>(EIGEN_LOG2E);
|
||||
x = pmadd(x, cst_log2e, e);
|
||||
} else {
|
||||
const Packet cst_ln2 = pset1<Packet>(M_LN2);
|
||||
const Packet cst_ln2 = pset1<Packet>(EIGEN_LN2);
|
||||
x = pmadd(e, cst_ln2, x);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<float>(M_LOG2E) * ::logf(float(a)));
|
||||
return half(static_cast<float>(EIGEN_LOG2E) * ::logf(float(a)));
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(const half& a) {
|
||||
|
||||
Reference in New Issue
Block a user