acosh.c 569 B

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