3 /* tanh(x) = (exp(x) - exp(-x))/(exp(x) + exp(-x))
4 * = (exp(2*x) - 1)/(exp(2*x) - 1 + 2)
5 * = (1 - exp(-2*x))/(exp(-2*x) - 1 + 2)
9 union {double f
; uint64_t i
;} u
= {.f
= x
};
16 u
.i
&= (uint64_t)-1/2;
21 /* |x| > log(3)/2 ~= 0.5493 or nan */
24 /* note: this branch avoids raising overflow */
30 } else if (w
> 0x3fd058ae) {
31 /* |x| > log(5/3)/2 ~= 0.2554 */
34 } else if (w
>= 0x00100000) {
35 /* |x| >= 0x1p-1022, up to 2ulp error in [0.1,0.2554] */
39 /* |x| is subnormal */
40 /* note: the branch above would not raise underflow in [0x1p-1023,0x1p-1022) */