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

  1. /*                            atanh.c
  2.  *
  3.  *    Inverse hyperbolic tangent
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * double x, y, atanh();
  10.  *
  11.  * y = atanh( x );
  12.  *
  13.  *
  14.  *
  15.  * DESCRIPTION:
  16.  *
  17.  * Returns inverse hyperbolic tangent of argument in the range
  18.  * MINLOG to MAXLOG.
  19.  *
  20.  * If |x| < 0.5, the rational form x + x**3 P(x)/Q(x) is
  21.  * employed.  Otherwise,
  22.  *        atanh(x) = 0.5 * log( (1+x)/(1-x) ).
  23.  *
  24.  *
  25.  *
  26.  * ACCURACY:
  27.  *
  28.  *                      Relative error:
  29.  * arithmetic   domain     # trials      peak         rms
  30.  *    DEC        0,1        10000       3.0e-17     6.5e-18
  31.  *    IEEE      -1,1        30000       1.9e-16     5.2e-17
  32.  *
  33.  */
  34.  
  35. /*                        atanh.c    */
  36.  
  37.  
  38. /*
  39. Cephes Math Library Release 2.0:  April, 1987
  40. Copyright (C) 1987 by Stephen L. Moshier
  41. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  42. */
  43.  
  44. #include "mconf.h"
  45.  
  46. #ifdef UNK
  47. static double P[] = {
  48. -8.54074331929669305196E-1,
  49.  1.20426861384072379242E1,
  50. -4.61252884198732692637E1,
  51.  6.54566728676544377376E1,
  52. -3.09092539379866942570E1
  53. };
  54. static double Q[] = {
  55. /* 1.00000000000000000000E0,*/
  56. -1.95638849376911654834E1,
  57.  1.08938092147140262656E2,
  58. -2.49839401325893582852E2,
  59.  2.52006675691344555838E2,
  60. -9.27277618139601130017E1
  61. };
  62. #endif
  63. #ifdef DEC
  64. static short P[] = {
  65. 0140132,0122235,0105775,0130300,
  66. 0041100,0127327,0124407,0034722,
  67. 0141470,0100113,0115607,0130535,
  68. 0041602,0164721,0003257,0013673,
  69. 0141367,0043046,0166673,0045750
  70. };
  71. static short Q[] = {
  72. /*0040200,0000000,0000000,0000000,*/
  73. 0141234,0101326,0015460,0134564,
  74. 0041731,0160115,0116451,0032045,
  75. 0142171,0153343,0000532,0167226,
  76. 0042174,0000665,0077604,0000310,
  77. 0141671,0072235,0031114,0074377
  78. };
  79. #endif
  80.  
  81. #ifdef IBMPC
  82. static short P[] = {
  83. 0xb618,0xb17f,0x5493,0xbfeb,
  84. 0xe73a,0xf520,0x15da,0x4028,
  85. 0xf62c,0x7370,0x1009,0xc047,
  86. 0xe2f7,0x20d5,0x5d3a,0x4050,
  87. 0x697d,0xddb7,0xe8c4,0xc03e
  88. };
  89. static short Q[] = {
  90. /*0x0000,0x0000,0x0000,0x3ff0,*/
  91. 0x172f,0xc366,0x905a,0xc033,
  92. 0x2685,0xb3a5,0x3c09,0x405b,
  93. 0x5dd3,0x602b,0x3adc,0xc06f,
  94. 0x8019,0xaff0,0x8036,0x406f,
  95. 0x8f20,0xa649,0x2e93,0xc057
  96. };
  97. #endif
  98.  
  99. #ifdef MIEEE
  100. static short P[] = {
  101. 0xbfeb,0x5493,0xb17f,0xb618,
  102. 0x4028,0x15da,0xf520,0xe73a,
  103. 0xc047,0x1009,0x7370,0xf62c,
  104. 0x4050,0x5d3a,0x20d5,0xe2f7,
  105. 0xc03e,0xe8c4,0xddb7,0x697d
  106. };
  107. static short Q[] = {
  108. 0xc033,0x905a,0xc366,0x172f,
  109. 0x405b,0x3c09,0xb3a5,0x2685,
  110. 0xc06f,0x3adc,0x602b,0x5dd3,
  111. 0x406f,0x8036,0xaff0,0x8019,
  112. 0xc057,0x2e93,0xa649,0x8f20
  113. };
  114. #endif
  115.  
  116. extern double MAXNUM;
  117.  
  118. double atanh(x)
  119. double x;
  120. {
  121. double s, z;
  122. int i, n;
  123. double fabs(), log(), polevl(), p1evl();
  124.  
  125. z = fabs(x);
  126. if( z >= 1.0 )
  127.     {
  128.     if( x == 1.0 )
  129.         return( MAXNUM );
  130.     if( x == -1.0 )
  131.         return( -MAXNUM );
  132.     mtherr( "atanh", DOMAIN );
  133.     return( MAXNUM );
  134.     }
  135.  
  136. if( z < 1.0e-7 )
  137.     return(x);
  138.  
  139. if( z < 0.5 )
  140.     {
  141.     z = x * x;
  142.     s = x   +  x * z * (polevl(z, P, 4) / p1evl(z, Q, 5));
  143.     return(s);
  144.     }
  145.  
  146. return( 0.5 * log((1.0+x)/(1.0-x)) );
  147. }
  148.