1#include "libm.h" 2 3#if FLT_EVAL_METHOD == 2 4#undef sqrt 5#define sqrt sqrtl 6#endif 7 8/* acosh(x) = log(x + sqrt(x*x-1)) */ 9double acosh(double x) { 10 union { 11 double f; 12 uint64_t i; 13 } u = {.f = x}; 14 unsigned e = u.i >> 52 & 0x7ff; 15 16 /* x < 1 domain error is handled in the called functions */ 17 18 if (e < 0x3ff + 1) /* |x| < 2, up to 2ulp error in [1,1.125] */ 19 return log1p(x - 1 + sqrt((x - 1) * (x - 1) + 2 * (x - 1))); 20 if (e < 0x3ff + 26) /* |x| < 0x1p26 */ 21 return log(2 * x - 1 / (x + sqrt(x * x - 1))); 22 /* |x| >= 0x1p26 or nan */ 23 return log(x) + 0.693147180559945309417232121458176568; 24} 25