rework langinfo code for ABI compat and for use by time code
[musl] / src / math / atanh.c
1 #include "libm.h"
2
3 /* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */
4 double atanh(double x)
5 {
6         union {double f; uint64_t i;} u = {.f = x};
7         unsigned e = u.i >> 52 & 0x7ff;
8         unsigned s = u.i >> 63;
9
10         /* |x| */
11         u.i &= (uint64_t)-1/2;
12         x = u.f;
13
14         if (e < 0x3ff - 1) {
15                 /* |x| < 0.5, up to 1.7ulp error */
16                 x = 0.5*log1p(2*x + 2*x*x/(1-x));
17         } else {
18                 x = 0.5*log1p(2*x/(1-x));
19         }
20         return s ? -x : x;
21 }