#include "libm.h"12/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */3double __cdecl atanh(double x)4{5union {double f; uint64_t i;} u = {.f = x};6unsigned e = u.i >> 52 & 0x7ff;7unsigned s = u.i >> 63;8double_t y;910/* |x| */11u.i &= (uint64_t)-1/2;12y = u.f;1314if (e < 0x3ff - 1) {15if (e < 0x3ff - 32) {16fp_barrier(y + 0x1p120f);17/* handle underflow */18if (e == 0)19FORCE_EVAL((float)y);20} else {21/* |x| < 0.5, up to 1.7ulp error */22y = 0.5*log1p(2*y + 2*y*y/(1-y));23}24} else {25/* avoid overflow */26y = 0.5*log1p(2*(y/(1-y)));27if (isinf(y)) errno = ERANGE;28}29return s ? -y : y;30}313233