sinhl.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* sinhl.c
  2. *
  3. * Hyperbolic sine, long double precision
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * long double x, y, sinhl();
  10. *
  11. * y = sinhl( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns hyperbolic sine of argument in the range MINLOGL to
  18. * MAXLOGL.
  19. *
  20. * The range is partitioned into two segments. If |x| <= 1, a
  21. * rational function of the form x + x**3 P(x)/Q(x) is employed.
  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 -2,2 10000 1.5e-19 3.9e-20
  31. * IEEE +-10000 30000 1.1e-19 2.8e-20
  32. *
  33. */
  34. /*
  35. Cephes Math Library Release 2.7: January, 1998
  36. Copyright 1984, 1991, 1998 by Stephen L. Moshier
  37. */
  38. #include <math.h>
  39. #ifdef UNK
  40. static long double P[] = {
  41. 1.7550769032975377032681E-6L,
  42. 4.1680702175874268714539E-4L,
  43. 3.0993532520425419002409E-2L,
  44. 9.9999999999999999998002E-1L,
  45. };
  46. static long double Q[] = {
  47. 1.7453965448620151484660E-8L,
  48. -5.9116673682651952419571E-6L,
  49. 1.0599252315677389339530E-3L,
  50. -1.1403880487744749056675E-1L,
  51. 6.0000000000000000000200E0L,
  52. };
  53. #endif
  54. #ifdef IBMPC
  55. static short P[] = {
  56. 0xec6a,0xd942,0xfbb3,0xeb8f,0x3feb, XPD
  57. 0x365e,0xb30a,0xe437,0xda86,0x3ff3, XPD
  58. 0x8890,0x01f6,0x2612,0xfde6,0x3ff9, XPD
  59. 0x0000,0x0000,0x0000,0x8000,0x3fff, XPD
  60. };
  61. static short Q[] = {
  62. 0x4edd,0x4c21,0xad09,0x95ed,0x3fe5, XPD
  63. 0x4376,0x9b70,0xd605,0xc65c,0xbfed, XPD
  64. 0xc8ad,0x5d21,0x3069,0x8aed,0x3ff5, XPD
  65. 0x9c32,0x6374,0x2d4b,0xe98d,0xbffb, XPD
  66. 0x0000,0x0000,0x0000,0xc000,0x4001, XPD
  67. };
  68. #endif
  69. #ifdef MIEEE
  70. static long P[] = {
  71. 0x3feb0000,0xeb8ffbb3,0xd942ec6a,
  72. 0x3ff30000,0xda86e437,0xb30a365e,
  73. 0x3ff90000,0xfde62612,0x01f68890,
  74. 0x3fff0000,0x80000000,0x00000000,
  75. };
  76. static long Q[] = {
  77. 0x3fe50000,0x95edad09,0x4c214edd,
  78. 0xbfed0000,0xc65cd605,0x9b704376,
  79. 0x3ff50000,0x8aed3069,0x5d21c8ad,
  80. 0xbffb0000,0xe98d2d4b,0x63749c32,
  81. 0x40010000,0xc0000000,0x00000000,
  82. };
  83. #endif
  84. extern long double MAXNUML, MAXLOGL, MINLOGL, LOGE2L;
  85. #ifdef ANSIPROT
  86. extern long double fabsl ( long double );
  87. extern long double expl ( long double );
  88. extern long double polevll ( long double, void *, int );
  89. extern long double p1evll ( long double, void *, int );
  90. #else
  91. long double fabsl(), expl(), polevll(), p1evll();
  92. #endif
  93. #ifdef INFINITIES
  94. extern long double INFINITYL;
  95. #endif
  96. #ifdef NANS
  97. extern long double NANL;
  98. #endif
  99. long double sinhl(x)
  100. long double x;
  101. {
  102. long double a;
  103. #ifdef MINUSZERO
  104. if( x == 0.0 )
  105. return(x);
  106. #endif
  107. a = fabsl(x);
  108. if( (x > (MAXLOGL + LOGE2L)) || (x > -(MINLOGL-LOGE2L) ) )
  109. {
  110. mtherr( "sinhl", DOMAIN );
  111. #ifdef INFINITIES
  112. if( x > 0.0L )
  113. return( INFINITYL );
  114. else
  115. return( -INFINITYL );
  116. #else
  117. if( x > 0.0L )
  118. return( MAXNUML );
  119. else
  120. return( -MAXNUML );
  121. #endif
  122. }
  123. if( a > 1.0L )
  124. {
  125. if( a >= (MAXLOGL - LOGE2L) )
  126. {
  127. a = expl(0.5L*a);
  128. a = (0.5L * a) * a;
  129. if( x < 0.0L )
  130. a = -a;
  131. return(a);
  132. }
  133. a = expl(a);
  134. a = 0.5L*a - (0.5L/a);
  135. if( x < 0.0L )
  136. a = -a;
  137. return(a);
  138. }
  139. a *= a;
  140. return( x + x * a * (polevll(a,P,3)/polevll(a,Q,4)) );
  141. }