• https://me.yahoo.com

# atan2

Arc tangent function of two variables

## Interface

#include <math.h>double atan2 (double y, double x)long atan2l (long double y, long double x)float atan2f (float y, float x)

## Description

The atan2 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. It produces correct results even when the resulting angle is near $\inline&space;&space;\pi/2$ or $\inline&space;&space;-\pi/2$ (for x near 0).

Example:
##### Example - Arc tangent function of two variables
Workings
#include <stdio.h>
#include <math.h>
int main(void)
{
double result, x = 90.0, y = 15.0;
result = atan2(y, x);
printf("The arc tangent ratio of %lf is %lf\n", (y/x), result);
return 0;
}
Solution
Output:

The arc tangent ratio of 0.166667 is 0.165149

## Special Values

atan2 ( ±0, -0 ) returns ±$\inline&space;\pi$.

atan2 ( ±0, +0 ) returns ±0.

atan2 ( ±0, x ) returns ±$\inline&space;\pi$ for x < 0.

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

atan2 ( ±0 ) returns $\inline&space;-\pi/2$ for y > 0.

atan2 ( ±y, -∞ ) returns ±$\inline&space;\pi$ for finite y > 0.

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

atan2 ( ±∞, +x ) returns ±$\inline&space;\pi/2$ for finite x

atan2 ( ±∞, -∞ ) returns ±$\inline&space;3\pi/4$.

atan2 ( ±∞, +∞ ) returns ±$\inline&space;\pi/4$.

## Notes

The atan2 function is used mostly to convert from rectangular (x,y) to polar (r, $\inline&space;&space;\theta$) coordinates that must satisfy $\inline&space;x=r&space;\cos(\theta)$ and $\inline&space;y=r&space;\sin(\theta)$. In general, conversions to polar coordinates should be computed thus:
$r&space;:=&space;\sqrt{x^2&space;+&space;y^2}$
$\theta&space;:=&space;\mathrm{atan2}(y,x)$

## Standards

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