coshf.c 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* coshf.c
  2. *
  3. * Hyperbolic cosine
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, coshf();
  10. *
  11. * y = coshf( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns hyperbolic cosine of argument in the range MINLOGF to
  18. * MAXLOGF.
  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 +-MAXLOGF 100000 1.2e-7 2.8e-8
  29. *
  30. *
  31. * ERROR MESSAGES:
  32. *
  33. * message condition value returned
  34. * coshf overflow |x| > MAXLOGF MAXNUMF
  35. *
  36. *
  37. */
  38. /* cosh.c */
  39. /*
  40. Cephes Math Library Release 2.2: June, 1992
  41. Copyright 1985, 1987, 1992 by Stephen L. Moshier
  42. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  43. */
  44. #include <math.h>
  45. extern float MAXLOGF, MAXNUMF;
  46. float expf(float);
  47. float coshf(float xx)
  48. {
  49. float x, y;
  50. x = xx;
  51. if( x < 0 )
  52. x = -x;
  53. if( x > MAXLOGF )
  54. {
  55. mtherr( "coshf", OVERFLOW );
  56. return( MAXNUMF );
  57. }
  58. y = expf(x);
  59. y = y + 1.0/y;
  60. return( 0.5*y );
  61. }