double
atan2(
double y
, double x
)
float
atan2f(
float y
, float x
)
)
and
atan2f(
)
functions compute the principal value of the arc tangent of
y/x,
using the signs of both arguments to determine the quadrant of
the return value.
)
function, if successful,
returns the arc tangent of
y/x
in the range
[-,+]
radians.
If both
x
and
y
are zero, the global variable
errno
is set to
EDOM
.
On the
VAX:
atan2(
y , x , := | )
atan(
y/x |
)
defines "if x > 0,"
atan2(
0
, 0
)
= 0 on a
VAX
despite that previously
atan2(
0
, 0
)
may have generated an error message.
The reasons for assigning a value to
atan2(
0
, 0
)
are these:
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.
)
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)
on a VAX.
In general, conversions to polar coordinates should be computed thus:
r := hypot(x,y); ... := sqrt(x*x+y*y) theta := atan2(y,x).
)
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);
)
function conforms to
ANSI X3.159-1989 (``ANSI C89'') .