Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
atan2() |
Compute arc tangent | (·) | <math.h> |
C89 | C90 | C95 | C99 | C11 | |||
atan2() |
Compute arc tangent | M | (·) | <tgmath.h> |
C99 | C11 | |||||
atan2f() |
Compute arc tangent | (·) | <math.h> |
C99 | C11 | ||||||
atan2l() |
Compute arc tangent | (·) | <math.h> |
C99 | C11 | ||||||
hypot() |
Compute hypotenuse | (·) | <math.h> |
C99 | C11 | ||||||
hypot() |
Compute hypotenuse | M | (·) | <tgmath.h> |
C99 | C11 | |||||
hypotf() |
Compute hypotenuse | (·) | <math.h> |
C99 | C11 | ||||||
hypotl() |
Compute hypotenuse | (·) | <math.h> |
C99 | C11 |
To convert a Cartesian co-ordinate pair x,y into polar co-ordinates r (radius) and θ (argument or azimuth):
double x, y; double r = sqrt(x * x, y * y); // or double r = hypot(x, y); double theta = atan2(y, x);
For the inverse conversion:
double r, theta; double x = r * cos(theta); double y = r * sin(theta);
One can also convert a pair of Cartesian co-ordinates into
a complex
number, and use carg
and cabs
to get the angle and radius.
#include <math.h>
float atan2f(float y, float x);
double atan2(double y, double x);
long double atan2l(long double y, long double x);
#include <tgmath.h>
real-floating-type atan2(real-floating-type y, real-floating-type x);
The
atan2
functions take a co-ordinate pair
(x, y), and return the angle formed by
this point, the origin, and any point on the positive
x axis, in the range [−π, +π]. The result has the
same sign as y, and a magnitude greater than ½π if
x is negative.
#include <math.h>
float hypotf(float x, float y);
double hypot(double x, double y);
long double hypotl(long double x, long double y);
#include <tgmath.h>
real-floating-type hypot(real-floating-type x, real-floating-type y);
The
hypot
functions take a co-ordinate pair
(x, y), and return the distance between
this point and the origin, √(x² +
y²).