C atan2()

The atan2() function defined in the math.h header file. It helps to return the arc tangent value of the given number in radians. This function takes two arguments 'x-coordinate' and 'y-coordinate' and determines the correct quadrant based on the signs of both values.

double atan2(double y, double x); #where x &y are floating point values

Also, two functions atan2f() and atan2l() were used with type float and long double respectively.

float atan2f(float y,float x); 
long double atan2l(long double y,long double x); 

atan2() Parameters:

The atan2() function takes two parameters and it should be any number, either positive or negative.

Parameter Description Required / Optional
x floating-point value representing an x-  coordinate  Required
y      floating-point value representing a y-coordinate Required 

atan2() Return Value

The return value of atan2() function is a number in the interval [-pi,+pi] in radians.

Input Return Value
any positive or negative number a number in the interval [-pi,+pi]

Examples of atan2() 

Example 1: Working of atan2() function in C?

#include <stdio.h>
#include <math.h>
#define PI 3.141592654

int main()
  double x, y, output;
  y = 2.53;
  x = -10.2;
  output = atan2(y, x);
  output = output * 180.0/PI;

  printf("The Tangent inverse for(x = %.1lf, y = %.1lf) is %.1lf degrees.", x, y, output);
  return 0;


The Tangent inverse for(x = -10.2, y = 2.53) is 166.1 degrees. 

Example 2: How atan2() function worked in C?

#include <stdio.h>
#include <math.h>
#define PI 3.14159265

int main () {
   double x, y, out, value;

   x = -7.0;
   y = 7.0;
   value = 180.0 / PI;

   out = atan2 (y,x) * value;
   printf("Arc tangent of x = %lf, y = %lf ", x, y);
   printf("is %lf degrees\n", out);


Arc tangent of x = -7.000000, y = 7.000000 is 135.000000 degrees