summaryrefslogtreecommitdiffstatshomepage
path: root/lib/libm_dbl/tanh.c
blob: 6bdb7c39990c7f370b641b9d8c909e22e2eb7764 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
#include <math.h>

double tanh(double x) {
    int sign = 0;
    if (x < 0) {
        sign = 1;
        x = -x;
    }
    x = expm1(-2 * x);
    x = x / (x + 2);
    return sign ? x : -x;
}