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.
pull/4101/head
Damien George 2018-09-04 16:57:46 +10:00
rodzic 8014e7f15f
commit 0b239d458c
1 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

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