Calculates the trigonometric arc tangent function of
y/x
.
Include
<math.h>
Prototype
float atan2f (float y, float x);
Arguments
y
x
Return Value
Returns the arc tangent in radians in the range of -pi to pi with the quadrant determined by the signs of both parameters.
Remarks
A domain error occurs if both x
and y
are
zero or both x
and y
are +/- infinity.
Example
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
float x, y, z;
errno = 0;
x = 2.0F;
y = 0.0F;
z = atan2f (y, x);
if (errno)
perror("Error");
printf("The arctangent of %f/%f is %f\n", y, x, z);
errno = 0;
x = 0.0F;
y = -1.0F;
z = atan2f (y, x);
if (errno)
perror("Error");
printf("The arctangent of %f/%f is %f\n", y, x, z);
errno = 0;
x = 0.0F;
y = 0.0F;
z = atan2f (y, x);
if (errno)
perror("Error");
printf("The arctangent of %f/%f is %f\n", y, x, z);
}
Example Output
The arctangent of 2.000000/0.000000 is 1.570796
The arctangent of 0.000000/-1.000000 is 3.141593
Error: domain error
The arctangent of 0.000000/0.000000 is nan