Home >>C Math Functions >C math atan2() function
The C library function double atan2(double y, double x) is used to return the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant. It takes two arguments: x-coordinate and y-coordinate, and calculate the angle in radians for the quadrant. This function is defined in <math.h> header file.
Syntax:double atan2(double y, double x);
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double x, y, ret, val;
x = 0.75;
y = 0.555;
val = 180.0 / PI;
ret = atan2(y,x) * val;
printf("The arc tangent of x = %lf, y = %lf is %lf", x, y,ret);
return(0);
}
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double x, y, ret, val;
x = 0.75;
y = -0.555;
val = 180.0 / PI;
ret = atan2(y,x) * val;
printf("The arc tangent of x = %lf, y = %lf is %lf", x, y,ret);
return(0);
}