atan2()
Published Nov 30, 2022
Contribute to Docs
The atan2()
function returns the inverse tangent of the quotient of a coordinate pair (y/x), in radians.
Syntax
atan2(y, x)
The data type of the y
and x
parameters can be double
, float
, or long double
.
- The return value has the range of [-π, π].
- A negative value is returned if the
y
parameter is negative. - If both parameters are 0, then the value is 0.
Example
The following is an example of the atan2()
function and features an edge case:
#include <iostream>#include <cmath>int main() {double x = 10.0, y = 20.0;std::cout << atan2(y, x) << std::endl;x = 0.0, y = 0.0; // Edge Casestd::cout << atan2(y, x) << std::endl;return 0;}
This will produce the following output:
1.107150
Codebyte Example
The following example is runnable and features a negative y-coordinate:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C++ on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C++
Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.Beginner Friendly11 hours