Name
atan2, atan2f, atan2l
- arc tangent function of two variables
Library
libm.lib
Synopsis
|
double
atan2 (double y, double x);
|
|
float
atan2f (float y, float x);
|
|
long double
atan2 (long double y, long double x);
|
Return values
The
atan2,
atan2f,
and
atan2l
functions, if successful,
return the arc tangent of
y/ x
in the range
-words
[- pi, + pi]
radians.
Here are some of the special cases:
atan2 (y, x, No, :=, Ta);
|
atan (y/x, Ta);
if
x
> 0,
|
sign( y )*(pi -
|
atan (\*(Bay/x\*(Ba, ), Ta);
if
x
< 0,
|
|
0
if x = y = 0, or
|
|
sign( y )*\*(Pi/2
if
x
= 0 !=
y.
|
|
Detailed description
The
atan2
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.
The function
atan2l
is an alias to the function
atan2.
Examples
#include <math.h>
int main( void )
{
double x1 = -862.42, x2 = 78.5149, y;
y = atan2( x1, x2 );
printf( "atan2(%f , %f) = %f\n", x1, x2, y );
y = atan2f( x1, x2 );
printf( "atan2f(%f , %f) = %f\n", x1, x2, y );
y = atan2l( x1, x2 );
printf( "atan2l(%f , %f) = %f\n", x1, x2, y );
}
Output
atan2( -862.42, 78.5149 ) = -1.480006
atan2f( -862.42, 78.5149 ) = -1.480006
atan2l( -862.42, 78.5149 ) = -1.480006
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)
(r,th)
coordinates that must satisfy x =
r*cos theta
r*costh
and y =
r*sin theta.
r*sinth.
These equations are satisfied when (x=0,y=0)
is mapped to
(r=0,theta=0).
(r=0,th=0).
In general, conversions to polar coordinates
should be computed thus:
r := hypot(x,y); ... := sqrt(x*x+y*y)
theta := atan2(y,x).
r := hypot(x,y); ... := v/(x20+y20)
th := 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
and
atan2
provided for
such a machine are designed to handle all cases.
That is why
atan2 (±0, -0);
= ±pi
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);
r := v/(x*x+y*y); if r = 0 then x := copysign(1,x);
See also
acos,
asin,
atan,
cos,
cosh,
math,
sin,
sinh,
tan,
tanh
The
atan2
function conforms to
-isoC.
Feedback
For additional information or queries on this page send feedback
© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user. |
|