lib/libm_dbl/tanh: Make tanh more efficient and handle large numbers.

Prior to this patch tanh(large number) would return nan due to inf/inf.
This commit is contained in:
Damien George 2018-09-04 16:57:46 +10:00
parent 8014e7f15f
commit 0b239d458c

View File

@ -1,5 +1,12 @@
#include <math.h>
double tanh(double x) {
return sinh(x) / cosh(x);
int sign = 0;
if (x < 0) {
sign = 1;
x = -x;
}
x = expm1(-2 * x);
x = x / (x + 2);
return sign ? x : -x;
}