]> Git Repo - uclibc-ng.git/blob - libm/float/tandgf.c
dc55ad5e41ebb3adb03b625074a005f7fb55c3c8
[uclibc-ng.git] / libm / float / 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 <math.h>
85
86 extern float MAXNUMF;
87
88 static float T24M1 = 16777215.;
89 static float PI180 = 0.0174532925199432957692; /* pi/180 */
90
91 static float tancotf( float xx, int cotflg )
92 {
93 float x, y, z, zz;
94 long j;
95 int sign;
96
97
98 /* make argument positive but save the sign */
99 if( xx < 0.0 )
100         {
101         x = -xx;
102         sign = -1;
103         }
104 else
105         {
106         x = xx;
107         sign = 1;
108         }
109
110 if( x > T24M1 )
111         {
112         if( cotflg )
113                 mtherr( "cotdgf", TLOSS );
114         else
115                 mtherr( "tandgf", TLOSS );
116         return(0.0);
117         }
118
119 /* compute x mod PIO4 */
120 j = 0.022222222222222222222 * x; /* integer part of x/45 */
121 y = j;
122
123 /* map zeros and singularities to origin */
124 if( j & 1 )
125         {
126         j += 1;
127         y += 1.0;
128         }
129
130 z = x - y * 45.0;
131 z *= PI180;     /* multiply by pi/180 to convert to radians */
132
133 zz = z * z;
134
135 if( x > 1.0e-4 )
136         {
137 /* 1.7e-8 relative error in [-pi/4, +pi/4] */
138         y =
139         ((((( 9.38540185543E-3 * zz
140         + 3.11992232697E-3) * zz
141         + 2.44301354525E-2) * zz
142         + 5.34112807005E-2) * zz
143         + 1.33387994085E-1) * zz
144         + 3.33331568548E-1) * zz * z
145         + z;
146         }
147 else
148         {
149         y = z;
150         }
151
152 if( j & 2 )
153         {
154         if( cotflg )
155                 y = -y;
156         else
157                 {
158                 if( y != 0.0 )
159                         {
160                         y = -1.0/y;
161                         }
162                 else
163                         {
164                         mtherr( "tandgf", SING );
165                         y = MAXNUMF;
166                         }
167                 }
168         }
169 else
170         {
171         if( cotflg )
172                 {
173                 if( y != 0.0 )
174                         y = 1.0/y;
175                 else
176                         {
177                         mtherr( "cotdgf", SING );
178                         y = MAXNUMF;
179                         }
180                 }
181         }
182
183 if( sign < 0 )
184         y = -y;
185
186 return( y );
187 }
188
189
190 float tandgf( float x )
191 {
192
193 return( tancotf(x,0) );
194 }
195
196 float cotdgf( float x )
197 {
198
199 if( x == 0.0 )
200         {
201         mtherr( "cotdgf", SING );
202         return( MAXNUMF );
203         }
204 return( tancotf(x,1) );
205 }
206
This page took 0.025353 seconds and 2 git commands to generate.