atan2atan2f
- arc tangent functions of two variables
LIBRARY
Lb libm
SYNOPSIS
#include <math.h> double
atan2 (double y double x); float
atan2f (float y float x);
DESCRIPTION
The
atan2 ();
and the
atan2f ();
functions compute the principal value of the arc tangent of
Fa y/ Ns Ar x ,
using the signs of both arguments to determine the quadrant of
the return value.
RETURN VALUES
The
atan2 ();
and the
atan2f ();
functions, if successful,
return the arc tangent of
Fa y/ Ns Ar x
in the range
-words
Bq - Ns , + Ns
radians.
Here are some of the special cases:
Fn atan2 y x := Ta Fn atan y/x Ta if
x
> 0,
Ta sign( y )*(
atan (\*(Bay/x\*(Ba ) Ta);
if
x
< 0,
Ta 0 Ta if x = y = 0, or
Ta sign( y )*\*(Pi/2 Ta if
x
= 0 !=
y
NOTES
The function
atan2 ();
defines "if x > 0,"
atan2 (0 0);
= 0 despite that previously
atan2 (0 0);
may have generated an error message.
The reasons for assigning a value to
atan2 (0 0);
are these:
Programs that test arguments to avoid computing
atan2 (0 0);
must be indifferent to its value.
Programs that require it to be invalid are vulnerable
to diverse reactions to that invalidity on diverse computer systems.
The
atan2 ();
function is used mostly to convert from rectangular (x,y)
to polar
(r,theta)
coordinates that must satisfy x =
r*cos theta
and y =
r*sin theta.
These equations are satisfied when (x=0,y=0)
is mapped to
(r=0,theta=0).
In general, conversions to polar coordinates
should be computed thus:
r := hypot(x,y); ... := sqrt(x*x+y*y)
theta := atan2(y,x).
The foregoing formulas need not be altered to cope in a
reasonable way with signed zeros and infinities
on a machine that conforms to
IEEE 754
the versions of
hypot(3)
and
atan2 ();
provided for
such a machine are designed to handle all cases.
That is why
atan2 (±0 -0);
= ±
for instance.
In general the formulas above are equivalent to these:
r := sqrt(x*x+y*y); if r = 0 then x := copysign(1,x);