2 /* @(#)z_atangent.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 <<atan>>, <<atanf>>, <<atan2>>, <<atan2f>>, <<atangent>>, <<atangentf>>---arc tangent
25 double atan(double <[x]>);
26 float atan(float <[x]>);
27 double atan2(double <[y]>,double <[x]>);
28 float atan2f(float <[y]>,float <[x]>);
32 <<atan2>> computes the inverse tangent (arc tangent) of y / x.
34 <<atan2f>> is identical to <<atan2>>, save that it operates on <<floats>>.
36 <<atan>> computes the inverse tangent (arc tangent) of the input value.
38 <<atanf>> is identical to <<atan>>, save that it operates on <<floats>>.
42 <<atan>> returns a value in radians, in the range of -pi/2 to pi/2.
43 <<atan2>> returns a value in radians, in the range of -pi/2 to pi/2.
46 <<atan>> returns a value in radians, in the range of $-\pi/2$ to $\pi/2$.
47 <<atan2>> returns a value in radians, in the range of $-\pi/2$ to $\pi/2$.
51 <<atan>> is ANSI C. <<atanf>> is an extension.
52 <<atan2>> is ANSI C. <<atan2f>> is an extension.
56 /******************************************************************
60 * x - floating point value
66 * This routine calculates arctangents.
68 *****************************************************************/
73 #ifndef _DOUBLE_IS_32BITS
75 static const double ROOT3
= 1.73205080756887729353;
76 static const double a
[] = { 0.0, 0.52359877559829887308, 1.57079632679489661923,
77 1.04719755119659774615 };
78 static const double q
[] = { 0.41066306682575781263e+2,
79 0.86157349597130242515e+2,
80 0.59578436142597344465e+2,
81 0.15024001160028576121e+2 };
82 static const double p
[] = { -0.13688768894191926929e+2,
83 -0.20505855195861651981e+2,
84 -0.84946240351320683534e+1,
85 -0.83758299368150059274 };
93 double f
, g
, R
, P
, Q
, A
, res
;
98 /* Preparation for calculating arctan2. */
105 return (z_notanum
.d
);
116 /* Get the exponent values of the inputs. */
117 g
= frexp (v
, &expv
);
118 g
= frexp (u
, &expu
);
120 /* See if a divide will overflow. */
128 /* Also check for underflow. */
129 else if (e
< DBL_MIN_EXP
)
152 if (f
> (2.0 - ROOT3
))
155 f
= (((A
* f
- 0.5) - 0.5) + f
) / (ROOT3
+ f
);
159 /* Check for values that are too small. */
160 if (-z_rooteps
< f
&& f
< z_rooteps
)
163 /* Calculate the Taylor series. */
167 P
= (((p
[3] * g
+ p
[2]) * g
+ p
[1]) * g
+ p
[0]) * g
;
168 Q
= (((g
+ q
[3]) * g
+ q
[2]) * g
+ q
[1]) * g
+ q
[0];
195 #endif /* _DOUBLE_IS_32BITS */