diff options
author | Rasmus Munk Larsen <rmlarsen@google.com> | 2019-08-28 12:20:21 -0700 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2019-08-28 12:20:21 -0700 |
commit | 1187bb65ad196161a07f4e0125e478d022ea1b08 (patch) | |
tree | 86fa97b5b8f1f7377d51cdd202f30a4293b6b9ae /Eigen | |
parent | 6e77f9bef35012f160b307bdeae73194fde91e51 (diff) |
Add more tests for corner cases of log1p and expm1. Add handling of infinite arguments to log1p such that log1p(inf) = inf.
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/MathFunctions.h | 3 | ||||
-rw-r--r-- | Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index fcf62011e..fbec39d83 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -551,7 +551,8 @@ namespace std_fallback { Scalar x1p = RealScalar(1) + x; Scalar log_1p = log(x1p); const bool is_small = numext::equal_strict(x1p, Scalar(1)); - return is_small ? x : x * (log_1p / (x1p - RealScalar(1))); + const bool is_inf = numext::equal_strict(x1p, log_1p); + return (is_small || is_inf) ? x : x * (log_1p / (x1p - RealScalar(1))); } } diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 505a0eec8..0fc673e12 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -137,8 +137,9 @@ Packet generic_plog1p(const Packet& x) Packet xp1 = padd(x, one); Packet small_mask = pcmp_eq(xp1, one); Packet log1 = plog(xp1); + Packet inf_mask = pcmp_eq(xp1, log1); Packet log_large = pmul(x, pdiv(log1, psub(xp1, one))); - return pselect(small_mask, x, log_large); + return pselect(por(small_mask, inf_mask), x, log_large); } /** \internal \returns exp(x)-1 computed using W. Kahan's formula. |