OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / lib / libm / tandgf.c
1 /*                                                      tandgf.c
2  *
3  *      Circular tangent of angle in degrees
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * float x, y, tandgf();
10  *
11  * y = tandgf( x );
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Returns the circular tangent of the radian argument x.
18  *
19  * Range reduction is into intervals of 45 degrees.
20  *
21  *
22  *
23  *
24  * ACCURACY:
25  *
26  *                      Relative error:
27  * arithmetic   domain     # trials      peak         rms
28  *    IEEE     +-2^24       50000       2.4e-7      4.8e-8
29  *
30  * ERROR MESSAGES:
31  *
32  *   message         condition          value returned
33  * tanf total loss   x > 2^24              0.0
34  *
35  */
36 \f/*                                                     cotdgf.c
37  *
38  *      Circular cotangent of angle in degrees
39  *
40  *
41  *
42  * SYNOPSIS:
43  *
44  * float x, y, cotdgf();
45  *
46  * y = cotdgf( x );
47  *
48  *
49  *
50  * DESCRIPTION:
51  *
52  * Range reduction is into intervals of 45 degrees.
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     +-2^24       50000       2.4e-7      4.8e-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, 1992 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 T24M1 = 16777215.;
89 static float PI180 = 0.0174532925199432957692; /* pi/180 */
90
91 #ifdef ANSIC
92 static float tancotf( float xx, int cotflg )
93 #else
94 static float tancotf(xx,cotflg)
95 double xx;
96 int cotflg;
97 #endif
98 {
99 float x, y, z, zz;
100 long j;
101 int sign;
102
103
104 /* make argument positive but save the sign */
105 if( xx < 0.0 )
106         {
107         x = -xx;
108         sign = -1;
109         }
110 else
111         {
112         x = xx;
113         sign = 1;
114         }
115
116 if( x > T24M1 )
117         {
118         if( cotflg )
119                 mtherr( "cotdgf", TLOSS );
120         else
121                 mtherr( "tandgf", TLOSS );
122         return(0.0);
123         }
124
125 /* compute x mod PIO4 */
126 j = 0.022222222222222222222 * x; /* integer part of x/45 */
127 y = j;
128
129 /* map zeros and singularities to origin */
130 if( j & 1 )
131         {
132         j += 1;
133         y += 1.0;
134         }
135
136 z = x - y * 45.0;
137 z *= PI180;     /* multiply by pi/180 to convert to radians */
138
139 zz = z * z;
140
141 if( x > 1.0e-4 )
142         {
143 /* 1.7e-8 relative error in [-pi/4, +pi/4] */
144         y =
145         ((((( 9.38540185543E-3 * zz
146         + 3.11992232697E-3) * zz
147         + 2.44301354525E-2) * zz
148         + 5.34112807005E-2) * zz
149         + 1.33387994085E-1) * zz
150         + 3.33331568548E-1) * zz * z
151         + z;
152         }
153 else
154         {
155         y = z;
156         }
157
158 if( j & 2 )
159         {
160         if( cotflg )
161                 y = -y;
162         else
163                 {
164                 if( y != 0.0 )
165                         {
166                         y = -1.0/y;
167                         }
168                 else
169                         {
170                         mtherr( "tandgf", SING );
171                         y = MAXNUMF;
172                         }
173                 }
174         }
175 else
176         {
177         if( cotflg )
178                 {
179                 if( y != 0.0 )
180                         y = 1.0/y;
181                 else
182                         {
183                         mtherr( "cotdgf", SING );
184                         y = MAXNUMF;
185                         }
186                 }
187         }
188
189 if( sign < 0 )
190         y = -y;
191
192 return( y );
193 }
194
195
196 #ifdef ANSIC
197 float tandgf( float x )
198 #else
199 float tandgf(x)
200 double x;
201 #endif
202 {
203
204 return( tancotf(x,0) );
205 }
206
207 #ifdef ANSIC
208 float cotdgf( float x )
209 #else
210 float cotdgf(x)
211 double x;
212 #endif
213 {
214
215 if( x == 0.0 )
216         {
217         mtherr( "cotdgf", SING );
218         return( MAXNUMF );
219         }
220 return( tancotf(x,1) );
221 }
222