OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / lib / libm / tanf.c
1 /*                                                      tanf.c
2  *
3  *      Circular tangent
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * float x, y, tanf();
10  *
11  * y = tanf( x );
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Returns the circular tangent of the radian argument x.
18  *
19  * Range reduction is modulo pi/4.  A polynomial approximation
20  * is employed in the basic interval [0, pi/4].
21  *
22  *
23  *
24  * ACCURACY:
25  *
26  *                      Relative error:
27  * arithmetic   domain     # trials      peak         rms
28  *    IEEE     +-4096        100000     3.3e-7      4.5e-8
29  *
30  * ERROR MESSAGES:
31  *
32  *   message         condition          value returned
33  * tanf total loss   x > 2^24              0.0
34  *
35  */
36 \f/*                                                     cotf.c
37  *
38  *      Circular cotangent
39  *
40  *
41  *
42  * SYNOPSIS:
43  *
44  * float x, y, cotf();
45  *
46  * y = cotf( x );
47  *
48  *
49  *
50  * DESCRIPTION:
51  *
52  * Returns the circular cotangent of the radian argument x.
53  * A common routine computes either the tangent or cotangent.
54  *
55  *
56  *
57  * ACCURACY:
58  *
59  *                      Relative error:
60  * arithmetic   domain     # trials      peak         rms
61  *    IEEE     +-4096        100000     3.0e-7      4.5e-8
62  *
63  *
64  * ERROR MESSAGES:
65  *
66  *   message         condition          value returned
67  * cot total loss   x > 2^24                0.0
68  * cot singularity  x = 0                  MAXNUMF
69  *
70  */
71 \f
72 /*
73 Cephes Math Library Release 2.2:  June, 1992
74 Copyright 1984, 1987, 1989 by Stephen L. Moshier
75 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
76 */
77
78 /* Single precision circular tangent
79  * test interval: [-pi/4, +pi/4]
80  * trials: 10000
81  * peak relative error: 8.7e-8
82  * rms relative error: 2.8e-8
83  */
84 #include "mconf.h"
85
86 extern float MAXNUMF;
87
88 static float DP1 = 0.78515625;
89 static float DP2 = 2.4187564849853515625e-4;
90 static float DP3 = 3.77489497744594108e-8;
91 float FOPI = 1.27323954473516;  /* 4/pi */
92 static float lossth = 8192.;
93 /*static float T24M1 = 16777215.;*/
94
95
96 #ifdef ANSIC
97 static float tancotf( float xx, int cotflg )
98 #else
99 static float tancotf(xx,cotflg)
100 double xx;
101 int cotflg;
102 #endif
103 {
104 float x, y, z, zz;
105 long j;
106 int sign;
107
108
109 /* make argument positive but save the sign */
110 if( xx < 0.0 )
111         {
112         x = -xx;
113         sign = -1;
114         }
115 else
116         {
117         x = xx;
118         sign = 1;
119         }
120
121 if( x > lossth )
122         {
123         if( cotflg )
124                 mtherr( "cotf", TLOSS );
125         else
126                 mtherr( "tanf", TLOSS );
127         return(0.0);
128         }
129
130 /* compute x mod PIO4 */
131 j = FOPI * x; /* integer part of x/(PI/4) */
132 y = j;
133
134 /* map zeros and singularities to origin */
135 if( j & 1 )
136         {
137         j += 1;
138         y += 1.0;
139         }
140
141 z = ((x - y * DP1) - y * DP2) - y * DP3;
142
143 zz = z * z;
144
145 if( x > 1.0e-4 )
146         {
147 /* 1.7e-8 relative error in [-pi/4, +pi/4] */
148         y =
149         ((((( 9.38540185543E-3 * zz
150         + 3.11992232697E-3) * zz
151         + 2.44301354525E-2) * zz
152         + 5.34112807005E-2) * zz
153         + 1.33387994085E-1) * zz
154         + 3.33331568548E-1) * zz * z
155         + z;
156         }
157 else
158         {
159         y = z;
160         }
161
162 if( j & 2 )
163         {
164         if( cotflg )
165                 y = -y;
166         else
167                 y = -1.0/y;
168         }
169 else
170         {
171         if( cotflg )
172                 y = 1.0/y;
173         }
174
175 if( sign < 0 )
176         y = -y;
177
178 return( y );
179 }
180
181
182 #ifdef ANSIC
183 float tanf( float x )
184 #else
185 float tanf(x)
186 double x;
187 #endif
188 {
189
190 return( tancotf(x,0) );
191 }
192
193 #ifdef ANSIC
194 float cotf( float x )
195 #else
196 float cotf(x)
197 double x;
198 #endif
199 {
200
201 if( x == 0.0 )
202         {
203         mtherr( "cotf", SING );
204         return( MAXNUMF );
205         }
206 return( tancotf(x,1) );
207 }
208