English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C library function atan2() usage and example

C Standard Library - <math.h>

C library function double atan2(double y, double x) Returns the value in radians y/x The sign of y and x determines the correct quadrant.

Declaration

The following is atan2() function declaration.

double atan2(double y, double x)

Parameters

  • x  -- Represents the floating-point value of the x-axis coordinate.

  • y  -- Represents the floating-point value of the y-axis coordinate.

Return value

This function returns y in radians./The inverse tangent of x, the radian interval is [-pi,+pi].

Online example

The following example demonstrates atan2() function usage.

#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
   double x, y, ret, val;
   x = -7.0;
   y = 7.0;
   val = 180.0 / PI;
   ret = atan2 (y,x) * val;
   printf("x = %lf, y = %lf 的反正切", x, y);
   printf("Is %lf degrees\n", ret);
  
   return(0);
}

Let's compile and run the above program, which will produce the following result:

x = -7.000000, y = 7The arctan of .000000 is 135.000000 degrees

C Standard Library - <math.h>