coshl.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* coshl.c
  2. *
  3. * Hyperbolic cosine, long double precision
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * long double x, y, coshl();
  10. *
  11. * y = coshl( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns hyperbolic cosine of argument in the range MINLOGL to
  18. * MAXLOGL.
  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. * IEEE +-10000 30000 1.1e-19 2.8e-20
  29. *
  30. *
  31. * ERROR MESSAGES:
  32. *
  33. * message condition value returned
  34. * cosh overflow |x| > MAXLOGL+LOGE2L INFINITYL
  35. *
  36. *
  37. */
  38. /*
  39. Cephes Math Library Release 2.7: May, 1998
  40. Copyright 1985, 1991, 1998 by Stephen L. Moshier
  41. */
  42. #include <math.h>
  43. extern long double MAXLOGL, MAXNUML, LOGE2L;
  44. #ifdef ANSIPROT
  45. extern long double expl ( long double );
  46. extern int isnanl ( long double );
  47. #else
  48. long double expl(), isnanl();
  49. #endif
  50. #ifdef INFINITIES
  51. extern long double INFINITYL;
  52. #endif
  53. #ifdef NANS
  54. extern long double NANL;
  55. #endif
  56. long double coshl(x)
  57. long double x;
  58. {
  59. long double y;
  60. #ifdef NANS
  61. if( isnanl(x) )
  62. return(x);
  63. #endif
  64. if( x < 0 )
  65. x = -x;
  66. if( x > (MAXLOGL + LOGE2L) )
  67. {
  68. mtherr( "coshl", OVERFLOW );
  69. #ifdef INFINITIES
  70. return( INFINITYL );
  71. #else
  72. return( MAXNUML );
  73. #endif
  74. }
  75. if( x >= (MAXLOGL - LOGE2L) )
  76. {
  77. y = expl(0.5L * x);
  78. y = (0.5L * y) * y;
  79. return(y);
  80. }
  81. y = expl(x);
  82. y = 0.5L * (y + 1.0L / y);
  83. return( y );
  84. }