acosh.c 507 B

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