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

  1. /*                            atanhl.c
  2.  *
  3.  *    Inverse hyperbolic tangent, long double precision
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * long double x, y, atanhl();
  10.  *
  11.  * y = atanhl( x );
  12.  *
  13.  *
  14.  *
  15.  * DESCRIPTION:
  16.  *
  17.  * Returns inverse hyperbolic tangent of argument in the range
  18.  * MINLOGL to MAXLOGL.
  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.  *    IEEE      -1,1        30000       1.1e-19     3.3e-20
  31.  *
  32.  */
  33.  
  34.  
  35.  
  36. /*
  37. Cephes Math Library Release 2.2:  January, 1991
  38. Copyright (C) 1987, 1991 by Stephen L. Moshier
  39. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  40. */
  41.  
  42. #include "mconf.h"
  43.  
  44. #ifdef UNK
  45. static long double P[] = {
  46.  2.9647757819596835680719E-3L,
  47. -8.0026596513099094380633E-1L,
  48.  7.7920941408493040219831E0L,
  49. -2.4330686602187898836837E1L,
  50.  3.0204265014595622991082E1L,
  51. -1.2961142942114056581210E1L,
  52. };
  53. static long double Q[] = {
  54. /* 1.0000000000000000000000E0L,*/
  55. -1.3729634163247557081869E1L,
  56.  6.2320841104088512332185E1L,
  57. -1.2469344457045341444078E2L,
  58.  1.1394285233959210574352E2L,
  59. -3.8883428826342169425890E1L,
  60. };
  61. #endif
  62.  
  63. #ifdef IBMPC
  64. static short P[] = {
  65. 0x3aa2,0x036b,0xaf06,0xc24c,0x3ff6,
  66. 0x528e,0x56e8,0x3af4,0xccde,0xbffe,
  67. 0x9d89,0xc9a1,0xd5cf,0xf958,0x4001,
  68. 0xa653,0x6cfa,0x3f04,0xc2a5,0xc003,
  69. 0xc651,0x2b3d,0x55b2,0xf1a2,0x4003,
  70. 0xd76d,0xf293,0xd76b,0xcf60,0xc002,
  71. };
  72. static short Q[] = {
  73. /*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
  74. 0xd1b9,0x5314,0x94df,0xdbac,0xc002,
  75. 0x3caa,0x0517,0x8a92,0xf948,0x4004,
  76. 0x535e,0xaf5f,0x0b2a,0xf963,0xc005,
  77. 0xa6f9,0xb702,0xbd8a,0xe3e2,0x4005,
  78. 0xe136,0xf5ee,0xa190,0x9b88,0xc004,
  79. };
  80. #endif
  81.  
  82. #ifdef MIEEE
  83. static long P[] = {
  84. 0x3ff60000,0xc24caf06,0x036b3aa2,
  85. 0xbffe0000,0xccde3af4,0x56e8528e,
  86. 0x40010000,0xf958d5cf,0xc9a19d89,
  87. 0xc0030000,0xc2a53f04,0x6cfaa653,
  88. 0x40030000,0xf1a255b2,0x2b3dc651,
  89. 0xc0020000,0xcf60d76b,0xf293d76d,
  90. };
  91. static long Q[] = {
  92. /*0x3fff0000,0x80000000,0x00000000,*/
  93. 0xc0020000,0xdbac94df,0x5314d1b9,
  94. 0x40040000,0xf9488a92,0x05173caa,
  95. 0xc0050000,0xf9630b2a,0xaf5f535e,
  96. 0x40050000,0xe3e2bd8a,0xb702a6f9,
  97. 0xc0040000,0x9b88a190,0xf5eee136,
  98. };
  99. #endif
  100.  
  101. extern double MAXNUML;
  102.  
  103. long double atanhl(x)
  104. long double x;
  105. {
  106. long double s, z;
  107. int i, n;
  108. long double fabsl(), logl(), polevll(), p1evll();
  109.  
  110. z = fabsl(x);
  111. if( z >= 1.0L )
  112.     {
  113.     if( x == 1.0L )
  114.         return( MAXNUML );
  115.     if( x == -1.0L )
  116.         return( -MAXNUML );
  117.     mtherr( "atanhl", DOMAIN );
  118.     return( MAXNUML );
  119.     }
  120.  
  121. if( z < 1.0e-8L )
  122.     return(x);
  123.  
  124. if( z < 0.5L )
  125.     {
  126.     z = x * x;
  127.     s = x   +  x * z * (polevll(z, P, 5) / p1evll(z, Q, 5));
  128.     return(s);
  129.     }
  130.  
  131. return( 0.5L * logl((1.0L+x)/(1.0L-x)) );
  132. }
  133.