VOOZH about

URL: https://www.geeksforgeeks.org/cpp/atan2-function-in-c-stl/

⇱ atan2() function in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

atan2() function in C++ STL

Last Updated : 21 Jun, 2021

The atan2() is an inbuilt function in C++ STL which returns tangent inverse of (y/x), where y is the proportion of the y-coordinate and x is the proportion of the x-coordinate. The numeric value lies between -and representing the angle of a (x, y) point and positive x-axis. It is the counterclockwise angle, measured in radian, between the positive X-axis, and the point (x, y). 
Syntax: 
 

atan2(data_type y, data_type x)


Parameters:The function accepts two mandatory parameters which are described below: 
 

  • y - This value specifies y-coordinate.
  • x - This value specifies the x-coordinate.


The parameters can be of double, float or long double datatype. 
Return Value: The function returns a numeric value between -and representing the angle of a (x, y) point and positive x-axis. It is the counterclockwise angle, measured in radian, between the positive X-axis, and the point (x, y). 
Below programs illustrate the atan2() function: 
Program 1: 
 


Output: 
atan2(y/x) = 0.785398 radians
atan2(y/x) = 45 degrees

 

Program 2: 
 


Output: 
atan2(y/x) = 2.35619 radians
atan2(y/x) = 135 degrees

 

Program 3: 
 


Output: 
atan2(y/x) = 1.5708 radians
atan2(y/x) = 90 degrees

 

Program 4: 
 


Output: 
atan2(y/x) = 0 radians
atan2(y/x) = 0 degrees

 

Errors and Exceptions: The function returns no matching function for call to error when a string or character is passed as an argument. 
Program 5: 
 

Output: 
 

prog.cpp:9:26: error: no matching function for call to 'atan2(const char [2], double&)'
 result = atan2("1", x);


 

Comment
Article Tags: