sinh.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* sinh.c
  2. *
  3. * Hyperbolic sine
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double x, y, sinh();
  10. *
  11. * y = sinh( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns hyperbolic sine of argument in the range MINLOG to
  18. * MAXLOG.
  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. * DEC +- 88 50000 4.0e-17 7.7e-18
  31. * IEEE +-MAXLOG 30000 2.6e-16 5.7e-17
  32. *
  33. */
  34. /*
  35. Cephes Math Library Release 2.8: June, 2000
  36. Copyright 1984, 1995, 2000 by Stephen L. Moshier
  37. */
  38. #include <math.h>
  39. #ifdef UNK
  40. static double P[] = {
  41. -7.89474443963537015605E-1,
  42. -1.63725857525983828727E2,
  43. -1.15614435765005216044E4,
  44. -3.51754964808151394800E5
  45. };
  46. static double Q[] = {
  47. /* 1.00000000000000000000E0,*/
  48. -2.77711081420602794433E2,
  49. 3.61578279834431989373E4,
  50. -2.11052978884890840399E6
  51. };
  52. #endif
  53. #ifdef DEC
  54. static unsigned short P[] = {
  55. 0140112,0015377,0042731,0163255,
  56. 0142043,0134721,0146177,0123761,
  57. 0143464,0122706,0034353,0006017,
  58. 0144653,0140536,0157665,0054045
  59. };
  60. static unsigned short Q[] = {
  61. /*0040200,0000000,0000000,0000000,*/
  62. 0142212,0155404,0133513,0022040,
  63. 0044015,0036723,0173271,0011053,
  64. 0145400,0150407,0023710,0001034
  65. };
  66. #endif
  67. #ifdef IBMPC
  68. static unsigned short P[] = {
  69. 0x3cd6,0xe8bb,0x435f,0xbfe9,
  70. 0xf4fe,0x398f,0x773a,0xc064,
  71. 0x6182,0xc71d,0x94b8,0xc0c6,
  72. 0xab05,0xdbf6,0x782b,0xc115
  73. };
  74. static unsigned short Q[] = {
  75. /*0x0000,0x0000,0x0000,0x3ff0,*/
  76. 0x6484,0x96e9,0x5b60,0xc071,
  77. 0x2245,0x7ed7,0xa7ba,0x40e1,
  78. 0x0044,0xe4f9,0x1a20,0xc140
  79. };
  80. #endif
  81. #ifdef MIEEE
  82. static unsigned short P[] = {
  83. 0xbfe9,0x435f,0xe8bb,0x3cd6,
  84. 0xc064,0x773a,0x398f,0xf4fe,
  85. 0xc0c6,0x94b8,0xc71d,0x6182,
  86. 0xc115,0x782b,0xdbf6,0xab05
  87. };
  88. static unsigned short Q[] = {
  89. 0xc071,0x5b60,0x96e9,0x6484,
  90. 0x40e1,0xa7ba,0x7ed7,0x2245,
  91. 0xc140,0x1a20,0xe4f9,0x0044
  92. };
  93. #endif
  94. #ifdef ANSIPROT
  95. extern double fabs ( double );
  96. extern double exp ( double );
  97. extern double polevl ( double, void *, int );
  98. extern double p1evl ( double, void *, int );
  99. #else
  100. double fabs(), exp(), polevl(), p1evl();
  101. #endif
  102. extern double INFINITY, MINLOG, MAXLOG, LOGE2;
  103. double sinh(x)
  104. double x;
  105. {
  106. double a;
  107. #ifdef MINUSZERO
  108. if( x == 0.0 )
  109. return(x);
  110. #endif
  111. a = fabs(x);
  112. if( (x > (MAXLOG + LOGE2)) || (x > -(MINLOG-LOGE2) ) )
  113. {
  114. mtherr( "sinh", DOMAIN );
  115. if( x > 0 )
  116. return( INFINITY );
  117. else
  118. return( -INFINITY );
  119. }
  120. if( a > 1.0 )
  121. {
  122. if( a >= (MAXLOG - LOGE2) )
  123. {
  124. a = exp(0.5*a);
  125. a = (0.5 * a) * a;
  126. if( x < 0 )
  127. a = -a;
  128. return(a);
  129. }
  130. a = exp(a);
  131. a = 0.5*a - (0.5/a);
  132. if( x < 0 )
  133. a = -a;
  134. return(a);
  135. }
  136. a *= a;
  137. return( x + x * a * (polevl(a,P,3)/p1evl(a,Q,3)) );
  138. }