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:
parent
8014e7f15f
commit
0b239d458c
|
@ -1,5 +1,12 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
double tanh(double x) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue