atan(), atanf(), atanl(), atan2(), atan2f(), atan2l() — Calculate arctangent
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
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
- math.h
- acos(), acosf(), acosl() — Calculate arccosine
- acosh(), acoshf(), acoshl() — Calculate hyperbolic arccosine
- asin(), asinf(), asinl() — Calculate arcsine
- asinh(), asinhf(), asinhl() — Calculate hyperbolic arcsine
- atanh(), atanhf(), atanhl() — Calculate hyperbolic arctangent
- cos(), cosf(), cosl() — Calculate cosine
- cosh(), coshf(), coshl() — Calculate hyperbolic cosine
- sin(), sinf(), sinl() — Calculate sine
- sinh(), sinhf(), sinhl() — Calculate hyperbolic sine
- tan(), tanf(), tanl() — Calculate tangent
- tanh(), tanhf(), tanhl() — Calculate hyperbolic tangent