home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / cephes / cmath / asinh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-17  |  2.6 KB  |  147 lines

  1. /*                            asinh.c
  2.  *
  3.  *    Inverse hyperbolic sine
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * double x, y, asinh();
  10.  *
  11.  * y = asinh( x );
  12.  *
  13.  *
  14.  *
  15.  * DESCRIPTION:
  16.  *
  17.  * Returns inverse hyperbolic sine of argument.
  18.  *
  19.  * If |x| < 0.5, the function is approximated by a rational
  20.  * form  x + x**3 P(x)/Q(x).  Otherwise,
  21.  *
  22.  *     asinh(x) = log( x + sqrt(1 + x*x) ).
  23.  *
  24.  *
  25.  *
  26.  * ACCURACY:
  27.  *
  28.  *                      Relative error:
  29.  * arithmetic   domain     # trials      peak         rms
  30.  *    DEC       0,2         15000       4.7e-17     1.3e-17
  31.  *    IEEE     -1,1         30000       3.7e-16     7.8e-17
  32.  *    IEEE      1,3         30000       2.5e-16     6.7e-17
  33.  *
  34.  */
  35.  
  36. /*                        asinh.c    */
  37.  
  38. /*
  39. Cephes Math Library Release 2.1:  December, 1988
  40. Copyright 1984, 1987, 1988 by Stephen L. Moshier
  41. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  42. */
  43.  
  44.  
  45. #include "mconf.h"
  46.  
  47. #ifdef UNK
  48. static double P[] = {
  49. -4.33231683752342103572E-3,
  50. -5.91750212056387121207E-1,
  51. -4.37390226194356683570E0,
  52. -9.09030533308377316566E0,
  53. -5.56682227230859640450E0
  54. };
  55. static double Q[] = {
  56. /* 1.00000000000000000000E0,*/
  57.  1.28757002067426453537E1,
  58.  4.86042483805291788324E1,
  59.  6.95722521337257608734E1,
  60.  3.34009336338516356383E1
  61. };
  62. #endif
  63.  
  64. #ifdef DEC
  65. static short P[] = {
  66. 0136215,0173033,0110410,0105475,
  67. 0140027,0076361,0020056,0164520,
  68. 0140613,0173401,0160136,0053142,
  69. 0141021,0070744,0000503,0176261,
  70. 0140662,0021550,0073106,0133351
  71. };
  72. static short Q[] = {
  73. /* 0040200,0000000,0000000,0000000,*/
  74. 0041116,0001336,0034120,0173054,
  75. 0041502,0065300,0013144,0021231,
  76. 0041613,0022376,0035516,0153063,
  77. 0041405,0115216,0054265,0004557
  78. };
  79. #endif
  80.  
  81. #ifdef IBMPC
  82. static short P[] = {
  83. 0x1168,0x7221,0xbec3,0xbf71,
  84. 0xdd2a,0x2405,0xef9e,0xbfe2,
  85. 0xcacc,0x3c0b,0x7ee0,0xc011,
  86. 0x7f96,0x8028,0x2e3c,0xc022,
  87. 0xd6dd,0x0ec8,0x446d,0xc016
  88. };
  89. static short Q[] = {
  90. /* 0x0000,0x0000,0x0000,0x3ff0,*/
  91. 0x1ec5,0xc70a,0xc05b,0x4029,
  92. 0x8453,0x02cc,0x4d58,0x4048,
  93. 0xdac6,0xc769,0x649f,0x4051,
  94. 0xa12e,0xcb16,0xb351,0x4040
  95. };
  96. #endif
  97.  
  98. #ifdef MIEEE
  99. static short P[] = {
  100. 0xbf71,0xbec3,0x7221,0x1168,
  101. 0xbfe2,0xef9e,0x2405,0xdd2a,
  102. 0xc011,0x7ee0,0x3c0b,0xcacc,
  103. 0xc022,0x2e3c,0x8028,0x7f96,
  104. 0xc016,0x446d,0x0ec8,0xd6dd
  105. };
  106. static short Q[] = {
  107. 0x4029,0xc05b,0xc70a,0x1ec5,
  108. 0x4048,0x4d58,0x02cc,0x8453,
  109. 0x4051,0x649f,0xc769,0xdac6,
  110. 0x4040,0xb351,0xcb16,0xa12e
  111. };
  112. #endif
  113.  
  114. extern double LOGE2;
  115.  
  116. double asinh(x)
  117. double x;
  118. {
  119. double a, z;
  120. int sign;
  121. double log(), sqrt(), polevl(), p1evl();
  122.  
  123. if( x < 0.0 )
  124.     {
  125.     sign = -1;
  126.     x = -x;
  127.     }
  128. else
  129.     sign = 1;
  130.  
  131. if( x > 1.0e8 )
  132.     return( sign * (log(x) + LOGE2) );
  133.  
  134. z = x * x;
  135. if( x < 0.5 )
  136.     {
  137.     a = ( polevl(z, P, 4)/p1evl(z, Q, 4) ) * z;
  138.     a = a * x  +  x;
  139.     if( sign < 0 )
  140.         a = -a;
  141.     return(a);
  142.     }    
  143.  
  144. a = sqrt( z + 1.0 );
  145. return( sign * log(x + a) );
  146. }
  147.