mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add more tests for corner cases of log1p and expm1. Add handling of infinite arguments to log1p such that log1p(inf) = inf.
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user