cosh.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* cosh.c
  2. *
  3. * Hyperbolic cosine
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double x, y, cosh();
  10. *
  11. * y = cosh( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns hyperbolic cosine of argument in the range MINLOG to
  18. * MAXLOG.
  19. *
  20. * cosh(x) = ( exp(x) + exp(-x) )/2.
  21. *
  22. *
  23. *
  24. * ACCURACY:
  25. *
  26. * Relative error:
  27. * arithmetic domain # trials peak rms
  28. * DEC +- 88 50000 4.0e-17 7.7e-18
  29. * IEEE +-MAXLOG 30000 2.6e-16 5.7e-17
  30. *
  31. *
  32. * ERROR MESSAGES:
  33. *
  34. * message condition value returned
  35. * cosh overflow |x| > MAXLOG MAXNUM
  36. *
  37. *
  38. */
  39. /* cosh.c */
  40. /*
  41. Cephes Math Library Release 2.8: June, 2000
  42. Copyright 1985, 1995, 2000 by Stephen L. Moshier
  43. */
  44. #include "mconf.h"
  45. #ifdef ANSIPROT
  46. extern double exp(double);
  47. extern int isnan(double);
  48. extern int isfinite(double);
  49. #else
  50. double exp();
  51. int isnan(), isfinite();
  52. #endif
  53. extern double MAXLOG, INFINITY, LOGE2;
  54. double cosh(x) double x;
  55. {
  56. double y;
  57. #ifdef NANS
  58. if (isnan(x))
  59. return (x);
  60. #endif
  61. if (x < 0)
  62. x = -x;
  63. if (x > (MAXLOG + LOGE2)) {
  64. mtherr("cosh", OVERFLOW);
  65. return (INFINITY);
  66. }
  67. if (x >= (MAXLOG - LOGE2)) {
  68. y = exp(0.5 * x);
  69. y = (0.5 * y) * y;
  70. return (y);
  71. }
  72. y = exp(x);
  73. y = 0.5 * (y + 1.0 / y);
  74. return (y);
  75. }