Difference between revisions of "cpp/numeric/math/atan2"
m (typo) |
m (Text replace - "{{example cpp" to "{{example") |
||
Line 31: | Line 31: | ||
===Example=== | ===Example=== | ||
− | {{example | + | {{example |
| | | | ||
| code= | | code= |
Revision as of 17:05, 19 April 2012
Template:cpp/numeric/math/sidebar Template:ddcl list begin <tr class="t-dsc-header">
<td><cmath>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td ><td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">
<td ><td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">
<td ><td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">
<td ><td > (4) </td> <td > (since C++11) </td> </tr> Template:ddcl list end
Computes the inverse tangent of y/x
using the signs of arguments to correctly determine quadrant.
4) If any argument has integral type, it is cast to Template:cpp. If any other argument is Template:cpp, then the return type is Template:cpp, otherwise it is Template:cpp.
Contents |
Parameters
x, y | - | floating point value |
Return value
arc tangent of y/x
in radians in the range of [-π; π]
radians.
Example
#include <cmath> #include <utility> #include <iostream> std::pair<double, double> cartesian_to_polar(double x, double y) { return {std::hypot(x, y), std::atan2(y,x)}; } int main() { std::pair<double, double> polar = cartesian_to_polar(1, 1); std::cout << "(1,1) cartesian is (" << polar.first << "," << polar.second<< ") polar\n"; }
Output:
(1,1) cartesian is (1.41421,0.785398) polar