coshl.c 756 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "libm.h"
  2. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  3. long double coshl(long double x)
  4. {
  5. return cosh(x);
  6. }
  7. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  8. long double coshl(long double x)
  9. {
  10. union ldshape u = {x};
  11. unsigned ex = u.i.se & 0x7fff;
  12. uint32_t w;
  13. long double t;
  14. /* |x| */
  15. u.i.se = ex;
  16. x = u.f;
  17. w = u.i.m >> 32;
  18. /* |x| < log(2) */
  19. if (ex < 0x3fff-1 || (ex == 0x3fff-1 && w < 0xb17217f7)) {
  20. if (ex < 0x3fff-32) {
  21. FORCE_EVAL(x + 0x1p120f);
  22. return 1;
  23. }
  24. t = expm1l(x);
  25. return 1 + t*t/(2*(1+t));
  26. }
  27. /* |x| < log(LDBL_MAX) */
  28. if (ex < 0x3fff+13 || (ex == 0x3fff+13 && w < 0xb17217f7)) {
  29. t = expl(x);
  30. return 0.5*(t + 1/t);
  31. }
  32. /* |x| > log(LDBL_MAX) or nan */
  33. t = expl(0.5*x);
  34. return 0.5*t*t;
  35. }
  36. #endif