cosh.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <math.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)
  55. double x;
  56. {
  57. double y;
  58. #ifdef NANS
  59. if( isnan(x) )
  60. return(x);
  61. #endif
  62. if( x < 0 )
  63. x = -x;
  64. if( x > (MAXLOG + LOGE2) )
  65. {
  66. mtherr( "cosh", OVERFLOW );
  67. return( INFINITY );
  68. }
  69. if( x >= (MAXLOG - LOGE2) )
  70. {
  71. y = exp(0.5 * x);
  72. y = (0.5 * y) * y;
  73. return(y);
  74. }
  75. y = exp(x);
  76. y = 0.5 * (y + 1.0 / y);
  77. return( y );
  78. }