atan(), atanf(), atanl(), atan2(), atan2f(), atan2l() — Calculate arctangent

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

#include <math.h>

double atan(double x);
float atan(float x);                  /* C++ only */
long double atan(long double x);      /* C++ only */
float atanf(float x);
long double atanl(long double x);

double atan2(double y, double x);
float atan2(float y, float x);                    /* C++ only */
long double atan2(long double y, long double x);  /* C++ only */
float atan2f(float y, float x);
long double atan2l(long double y, long double x);

General description

The atan() and atan2() functions calculate the arctangent of x and y/x, respectively.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Restriction: The atan2f() function does not support the _FP_MODE_VARIABLE feature test macro.

Returned value

Returns a value in the range -pi/2 to pi/2 radians.

The atan2() functions return a value in the range -pi to pi radians. If both arguments of atan2() are zero, the function sets errno to EDOM, and returns 0. If the correct value would cause underflow, zero is returned and the value ERANGE is stored in errno.

Special behavior for IEEE: If successful, atan2() returns the arctangent of y/x.

If both arguments of atan2() are zero, the function sets errno to EDOM and returns 0. No other errors will occur.

Example

CELEBA09
⁄* CELEBA09 *⁄                                   
#include <math.h>                                                               
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
    double a,b,c,d;                                                             
                                                                                
    c = 0.45;                                                                   
    d = 0.23;                                                                   
                                                                                
    a = atan(c);                                                                
    b = atan2(c,d);                                                             
                                                                                
    printf("atan( %f ) = %f\n", c, a);                                          
    printf("atan2( %f, %f ) = %f\n", c, d, b);                                  
}                                                                               
Output
atan( 0.450000 ) = 0.422854
atan2( 0.450000, 0.230000 ) = 1.098299

Related information