OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / lib / libm / tanh.c
1 /*                                                      tanh.c
2  *
3  *      Hyperbolic tangent
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * double x, y, tanh();
10  *
11  * y = tanh( x );
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Returns hyperbolic tangent of argument in the range MINLOG to
18  * MAXLOG.
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  *    DEC       -2,2        50000       3.3e-17     6.4e-18
32  *    IEEE      -2,2        30000       2.5e-16     5.8e-17
33  *
34  */
35 \f
36 /*
37 Cephes Math Library Release 2.8:  June, 2000
38 Copyright 1984, 1995, 2000 by Stephen L. Moshier
39 */
40
41 #include "mconf.h"
42
43 #ifdef UNK
44 static double P[] = {
45 -9.64399179425052238628E-1,
46 -9.92877231001918586564E1,
47 -1.61468768441708447952E3
48 };
49 static double Q[] = {
50 /* 1.00000000000000000000E0,*/
51  1.12811678491632931402E2,
52  2.23548839060100448583E3,
53  4.84406305325125486048E3
54 };
55 #endif
56 #ifdef DEC
57 static unsigned short P[] = {
58 0140166,0161335,0053753,0075126,
59 0141706,0111520,0070463,0040552,
60 0142711,0153001,0101300,0025430
61 };
62 static unsigned short Q[] = {
63 /*0040200,0000000,0000000,0000000,*/
64 0041741,0117624,0051300,0156060,
65 0043013,0133720,0071251,0127717,
66 0043227,0060201,0021020,0020136
67 };
68 #endif
69
70 #ifdef IBMPC
71 static unsigned short P[] = {
72 0x6f4b,0xaafd,0xdc5b,0xbfee,
73 0x682d,0x0e26,0xd26a,0xc058,
74 0x0563,0x3058,0x3ac0,0xc099
75 };
76 static unsigned short Q[] = {
77 /*0x0000,0x0000,0x0000,0x3ff0,*/
78 0x1b86,0x8a58,0x33f2,0x405c,
79 0x35fa,0x0e55,0x76fa,0x40a1,
80 0x040c,0x2442,0xec10,0x40b2
81 };
82 #endif
83
84 #ifdef MIEEE
85 static unsigned short P[] = {
86 0xbfee,0xdc5b,0xaafd,0x6f4b,
87 0xc058,0xd26a,0x0e26,0x682d,
88 0xc099,0x3ac0,0x3058,0x0563
89 };
90 static unsigned short Q[] = {
91 0x405c,0x33f2,0x8a58,0x1b86,
92 0x40a1,0x76fa,0x0e55,0x35fa,
93 0x40b2,0xec10,0x2442,0x040c
94 };
95 #endif
96
97 #ifdef ANSIPROT
98 extern double fabs ( double );
99 extern double exp ( double );
100 extern double polevl ( double, void *, int );
101 extern double p1evl ( double, void *, int );
102 #else
103 double fabs(), exp(), polevl(), p1evl();
104 #endif
105 extern double MAXLOG;
106
107 double tanh(x)
108 double x;
109 {
110 double s, z;
111
112 #ifdef MINUSZERO
113 if( x == 0.0 )
114         return(x);
115 #endif
116 z = fabs(x);
117 if( z > 0.5 * MAXLOG )
118         {
119         if( x > 0 )
120                 return( 1.0 );
121         else
122                 return( -1.0 );
123         }
124 if( z >= 0.625 )
125         {
126         s = exp(2.0*z);
127         z =  1.0  - 2.0/(s + 1.0);
128         if( x < 0 )
129                 z = -z;
130         }
131 else
132         {
133         if( x == 0.0 )
134           return(x);
135         s = x * x;
136         z = polevl( s, P, 2 )/p1evl(s, Q, 3);
137         z = x * s * z;
138         z = x + z;
139         }
140 return( z );
141 }