Math module

atan2

procedure · 2 overloadsSource

The angle of the point (x, y) from the positive x axis in radians, in [-pi, pi], using the signs of both to pick the quadrant. Note the argument order: y first. atan2(0, x) is 0 for positive x and pi for negative x (negative pi when y is -0.0); atan2(0, 0) is 0. NaN in either argument gives NaN.

ExampleOpen in playground ↗
assert(abs(atan2(cast(float64) 1, cast(float64) 1) - PI64 / 4) < 0.000001);
assert(abs(atan2(cast(float64) 1, cast(float64) -1) - 3 * PI64 / 4) < 0.000001);
assert(abs(atan2(cast(float64) -1, cast(float64) 0) + PI64 / 2) < 0.000001);
atan2 :: (y: float64, x: float64) -> float64

Angle in radians of the point (x, y) from the positive x axis, between -pi and pi. Uses the signs of both to pick the quadrant.

Parameters

y: float64
the vertical component.
x: float64
the horizontal component.

Returns

float64
atan2 :: (y: float, x: float) -> float

Angle in radians of the point (x, y) from the positive x axis, between -pi and pi. Uses the signs of both to pick the quadrant.

Parameters

y: float
the vertical component.
x: float
the horizontal component.

Returns

float

See also