atan2, atan2f, atan2l

Header: <math.h>

1-6) Computes the arc tangent of y / x using the signs of arguments to determine the correct quadrant.

# Declarations

float atan2f( float y, float x );

(since C99)

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

(since C99)

_Decimal32 atan2d32( _Decimal32 y, _Decimal32 x );

(since C23)

_Decimal64 atan2d64( _Decimal64 y, _Decimal64 x );

(since C23)

_Decimal128 atan2d128( _Decimal128 y, _Decimal128 x );

(since C23)

#define atan2( y, x )

(since C99)

# Parameters

# Return value

If a domain error occurs, an implementation-defined value is returned.

# Notes

atan2(y, x) is equivalent to carg(x + I*y).

POSIX specifies that in case of underflow, y / x is the value returned, and if that is not supported, an implementation-defined value no greater than DBL_MIN, FLT_MIN, and LDBL_MIN is returned.

# Example

#include <math.h>
#include <stdio.h>
 
int main(void)
{
    // normal usage: the signs of the two arguments determine the quadrant
    // atan2(1,1) = +pi/4, Quad I
    printf("(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1), atan2( 1, 1));
    // atan2(1, -1) = +3pi/4, Quad II
    printf("(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1,-1), atan2( 1,-1));
    // atan2(-1,-1) = -3pi/4, Quad III
    printf("(-1,-1) cartesian is (%f,%f) polar\n", hypot(-1,-1), atan2(-1,-1));
    // atan2(-1,-1) = -pi/4, Quad IV
    printf("(-1,+1) cartesian is (%f,%f) polar\n", hypot(-1, 1), atan2(-1, 1));
 
    // special values
    printf("atan2(0, 0) = %f atan2(0, -0)=%f\n", atan2(0,0), atan2(0,-0.0));
    printf("atan2(7, 0) = %f atan2(7, -0)=%f\n", atan2(7,0), atan2(7,-0.0));
}

# See also