atan2()

shlokPrajapati60053717094 total contributions
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:
All contributors
- shlokPrajapati60053717094 total contributions
Looking to contribute?
- 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.