sinhf.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* sinhf.c
  2. *
  3. * Hyperbolic sine
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, sinhf();
  10. *
  11. * y = sinhf( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns hyperbolic sine of argument in the range MINLOGF to
  18. * MAXLOGF.
  19. *
  20. * The range is partitioned into two segments. If |x| <= 1, a
  21. * polynomial approximation is used.
  22. * Otherwise the calculation is sinh(x) = ( exp(x) - exp(-x) )/2.
  23. *
  24. *
  25. *
  26. * ACCURACY:
  27. *
  28. * Relative error:
  29. * arithmetic domain # trials peak rms
  30. * IEEE +-MAXLOG 100000 1.1e-7 2.9e-8
  31. *
  32. */
  33. /*
  34. Cephes Math Library Release 2.2: June, 1992
  35. Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier
  36. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  37. */
  38. /* Single precision hyperbolic sine
  39. * test interval: [-1, +1]
  40. * trials: 10000
  41. * peak relative error: 9.0e-8
  42. * rms relative error: 3.0e-8
  43. */
  44. #include <math.h>
  45. extern float MAXLOGF, MAXNUMF;
  46. float expf( float );
  47. float sinhf( float xx )
  48. {
  49. register float z;
  50. float x;
  51. x = xx;
  52. if( xx < 0 )
  53. z = -x;
  54. else
  55. z = x;
  56. if( z > MAXLOGF )
  57. {
  58. mtherr( "sinhf", DOMAIN );
  59. if( x > 0 )
  60. return( MAXNUMF );
  61. else
  62. return( -MAXNUMF );
  63. }
  64. if( z > 1.0 )
  65. {
  66. z = expf(z);
  67. z = 0.5*z - (0.5/z);
  68. if( x < 0 )
  69. z = -z;
  70. }
  71. else
  72. {
  73. z = x * x;
  74. z =
  75. (( 2.03721912945E-4 * z
  76. + 8.33028376239E-3) * z
  77. + 1.66667160211E-1) * z * x
  78. + x;
  79. }
  80. return( z );
  81. }