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

  1. /*                            tanhl.c
  2.  *
  3.  *    Hyperbolic tangent, long double precision
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * long double x, y, tanhl();
  10.  *
  11.  * y = tanhl( x );
  12.  *
  13.  *
  14.  *
  15.  * DESCRIPTION:
  16.  *
  17.  * Returns hyperbolic tangent of argument in the range MINLOGL to
  18.  * MAXLOGL.
  19.  *
  20.  * A rational function is used for |x| < 0.625.  The form
  21.  * x + x**3 P(x)/Q(x) of Cody _& Waite is employed.
  22.  * Otherwise,
  23.  *    tanh(x) = sinh(x)/cosh(x) = 1  -  2/(exp(2x) + 1).
  24.  *
  25.  *
  26.  *
  27.  * ACCURACY:
  28.  *
  29.  *                      Relative error:
  30.  * arithmetic   domain     # trials      peak         rms
  31.  *    IEEE      -2,2        30000       1.3e-19     2.4e-20
  32.  *
  33.  */
  34.  
  35. /*
  36. Cephes Math Library Release 2.1:  February, 1989
  37. Copyright 1984, 1987, 1989 by Stephen L. Moshier
  38. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  39. */
  40.  
  41. #include "mconf.h"
  42.  
  43. #ifdef UNK
  44. static long double P[] = {
  45. -6.8473739392677100872869E-5L,
  46. -9.5658283111794641589011E-1L,
  47. -8.4053568599672284488465E1L,
  48. -1.3080425704712825945553E3L,
  49. };
  50. static long double Q[] = {
  51. /* 1.0000000000000000000000E0L,*/
  52.  9.6259501838840336946872E1L,
  53.  1.8218117903645559060232E3L,
  54.  3.9241277114138477845780E3L,
  55. };
  56. #endif
  57.  
  58. #ifdef IBMPC
  59. static short P[] = {
  60. 0xd2a4,0x1b0c,0x8f15,0x8f99,0xbff1,
  61. 0x5959,0x9111,0x9cc7,0xf4e2,0xbffe,
  62. 0xb576,0xef5e,0x6d57,0xa81b,0xc005,
  63. 0xe3be,0xbfbd,0x5cbc,0xa381,0xc009,
  64. };
  65. static short Q[] = {
  66. /*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
  67. 0x687f,0xce24,0xdd6c,0xc084,0x4005,
  68. 0x3793,0xc95f,0xfa2f,0xe3b9,0x4009,
  69. 0xd5a2,0x1f9c,0x0b1b,0xf542,0x400a,
  70. };
  71. #endif
  72.  
  73. #ifdef MIEEE
  74. static long P[] = {
  75. 0xbff10000,0x8f998f15,0x1b0cd2a4,
  76. 0xbffe0000,0xf4e29cc7,0x91115959,
  77. 0xc0050000,0xa81b6d57,0xef5eb576,
  78. 0xc0090000,0xa3815cbc,0xbfbde3be,
  79. };
  80. static long Q[] = {
  81. /*0x3fff0000,0x80000000,0x00000000,*/
  82. 0x40050000,0xc084dd6c,0xce24687f,
  83. 0x40090000,0xe3b9fa2f,0xc95f3793,
  84. 0x400a0000,0xf5420b1b,0x1f9cd5a2,
  85. };
  86. #endif
  87.  
  88. extern long double MAXLOGL;
  89.  
  90. long double tanhl(x)
  91. long double x;
  92. {
  93. long double s, z;
  94. long double fabsl(), expl(), polevll(), p1evll();
  95.  
  96.  
  97. z = fabsl(x);
  98. if( z > 0.5L * MAXLOGL )
  99.     {
  100.     if( x > 0 )
  101.         return( 1.0L );
  102.     else
  103.         return( -1.0L );
  104.     }
  105. if( z >= 0.625L )
  106.     {
  107.     s = expl(2.0*z);
  108.     z =  1.0L  - 2.0/(s + 1.0L);
  109.     if( x < 0 )
  110.         z = -z;
  111.     }
  112. else
  113.     {
  114.     s = x * x;
  115.     z = polevll( s, P, 3 )/p1evll(s, Q, 3);
  116.     z = x * s * z;
  117.     z = x + z;
  118.     }
  119. return( z );
  120. }
  121.