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 double atan2(<[y]>,<[x]>);
36 float atan2f(<[y]>,<[x]>);
49 <<atan2>> computes the inverse tangent (arc tangent) of y / x.
51 <<atan2f>> is identical to <<atan2>>, save that it operates on <<floats>>.
53 <<atan>> computes the inverse tangent (arc tangent) of the input value.
55 <<atanf>> is identical to <<atan>>, save that it operates on <<floats>>.
59 <<atan>> returns a value in radians, in the range of -pi/2 to pi/2.
60 <<atan2>> returns a value in radians, in the range of -pi/2 to pi/2.
63 <<atan>> returns a value in radians, in the range of $-\pi/2$ to $\pi/2$.
64 <<atan2>> returns a value in radians, in the range of $-\pi/2$ to $\pi/2$.
68 <<atan>> is ANSI C. <<atanf>> is an extension.
69 <<atan2>> is ANSI C. <<atan2f>> is an extension.
73 /******************************************************************
77 * x - floating point value
83 * This routine calculates arctangents.
85 *****************************************************************/
90 #ifndef _DOUBLE_IS_32BITS
92 static const double ROOT3
= 1.73205080756887729353;
93 static const double a
[] = { 0.0, 0.52359877559829887308, 1.57079632679489661923,
94 1.04719755119659774615 };
95 static const double q
[] = { 0.41066306682575781263e+2,
96 0.86157349597130242515e+2,
97 0.59578436142597344465e+2,
98 0.15024001160028576121e+2 };
99 static const double p
[] = { -0.13688768894191926929e+2,
100 -0.20505855195861651981e+2,
101 -0.84946240351320683534e+1,
102 -0.83758299368150059274 };
105 _DEFUN (atangent
, (double, double, double, int),
111 double f
, g
, R
, P
, Q
, A
, res
;
116 /* Preparation for calculating arctan2. */
123 return (z_notanum
.d
);
134 /* Get the exponent values of the inputs. */
135 g
= frexp (v
, &expv
);
136 g
= frexp (u
, &expu
);
138 /* See if a divide will overflow. */
146 /* Also check for underflow. */
147 else if (e
< DBL_MIN_EXP
)
170 if (f
> (2.0 - ROOT3
))
173 f
= (((A
* f
- 0.5) - 0.5) + f
) / (ROOT3
+ f
);
177 /* Check for values that are too small. */
178 if (-z_rooteps
< f
&& f
< z_rooteps
)
181 /* Calculate the Taylor series. */
185 P
= (((p
[3] * g
+ p
[2]) * g
+ p
[1]) * g
+ p
[0]) * g
;
186 Q
= (((g
+ q
[3]) * g
+ q
[2]) * g
+ q
[1]) * g
+ q
[0];
200 if (u
< 0.0 || branch
== 2)
202 if (v
< 0.0 || branch
== 1)
213 #endif /* _DOUBLE_IS_32BITS */