ATAN2(3) Library Functions Manual ATAN2(3)

atan2arc tangent function of two variables

#include <math.h>

double
atan2(double y, double x);

long double
atan2l(long double y, long double x);

float
atan2f(float y, float x);

The () function computes the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value.

atan2(±0, -0) returns ±pi.

(±0, +0) returns ±0.

(±0, x) returns ±pi for x < 0.

(±0, x) returns ±0 for x > 0.

(y, ±0) returns +pi/2 for y > 0.

(y, ±0) returns -pi/2 for y < 0.

(±y, -infinity) returns ±pi for finite y > 0.

(±y, +infinity) returns ±0 for finite y > 0.

(±infinity, x) returns ±pi/2 for finite x.

(±infinity, -infinity) returns ±3*pi/4.

(±infinity, +infinity) returns ±pi/4.

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. In general, conversions to polar coordinates should be computed thus:

r	:= hypot(x,y);  ... := sqrt(x∗x+y∗y)
theta	:= atan2(y,x).

If you need to apply the atan2() function to SIMD vectors or arrays, using the following functions provided by the Accelerate.framework may give significantly better performance:

#include <Accelerate/Accelerate.h>

vFloat (vFloat y, vFloat x);
void (float *z, const float *y, const float *x, const int *n);
void (double *z, const double *y, const double *x, const int *n);

acos(3), asin(3), atan(3), cos(3), cosh(3), sin(3), sinh(3), tan(3), tanh(3), math(3),

The atan2() function conforms to ISO/IEC 9899:2011.

December 11, 2006 Mac OS X 12