2 /* @(#)z_tan.c 1.0 98/08/13 */
3 /******************************************************************
4 * The following routines are coded directly from the algorithms
5 * and coefficients given in "Software Manual for the Elementary
6 * Functions" by William J. Cody, Jr. and William Waite, Prentice
8 ******************************************************************/
12 <<tan>>, <<tanf>>---tangent
21 double tan(double <[x]>);
22 float tanf(float <[x]>);
25 <<tan>> computes the tangent of the argument <[x]>.
26 Angles are specified in radians.
28 <<tanf>> is identical, save that it takes and returns <<float>> values.
31 The tangent of <[x]> is returned.
34 <<tan>> is ANSI. <<tanf>> is an extension.
37 /******************************************************************
41 * x - floating point value
47 * This routine calculates the tangent of x.
49 *****************************************************************/
54 #ifndef _DOUBLE_IS_32BITS
56 static const double TWO_OVER_PI
= 0.63661977236758134308;
57 static const double p
[] = { -0.13338350006421960681,
58 0.34248878235890589960e-2,
59 -0.17861707342254426711e-4 };
60 static const double q
[] = { -0.46671683339755294240,
61 0.25663832289440112864e-1,
62 -0.31181531907010027307e-3,
63 0.49819433993786512270e-6 };
68 double y
, f
, g
, XN
, xnum
, xden
, res
;
71 /* Check for special values. */
84 /* Check for values that are out of our range. */
92 N
= (int) (x
* TWO_OVER_PI
- 0.5);
94 N
= (int) (x
* TWO_OVER_PI
+ 0.5);
98 f
= x
- N
* __PI_OVER_TWO
;
100 /* Check for values that are too small. */
101 if (-z_rooteps
< f
&& f
< z_rooteps
)
107 /* Calculate the polynomial. */
112 xnum
= f
* ((p
[2] * g
+ p
[1]) * g
+ p
[0]) * g
+ f
;
113 xden
= (((q
[3] * g
+ q
[2]) * g
+ q
[1]) * g
+ q
[0]) * g
+ 1.0;
129 #endif /* _DOUBLE_IS_32BITS */