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:
Rasmus Munk Larsen
2019-08-28 12:20:21 -07:00
parent 6e77f9bef3
commit 1187bb65ad
3 changed files with 17 additions and 3 deletions

View File

@@ -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)));
}
}

View File

@@ -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.