atan2

guppylang.std.math.atan2(y: float, x: float) → float | angle[source]

Return the four-quadrant inverse tangent of (y, x).

Returns a float in radians unless the expected return type is angle. The equations below express the result in radians.

For finite inputs with \(y \ne 0\), the mathematical definition is:

\[\begin{split}\operatorname{atan2}(y, x) = \begin{cases} \arctan(y/x) & x > 0, \\[5mu] \arctan(y/x) + \pi & x < 0 \text{ and } y > 0, \\[5mu] \arctan(y/x) - \pi & x < 0 \text{ and } y < 0, \\[5mu] +\pi/2 & x = 0 \text{ and } y > 0, \\[5mu] -\pi/2 & x = 0 \text{ and } y < 0. \end{cases}\end{split}\]

Signed-zero inputs follow the floating-point conventions:

\[\begin{split}\operatorname{atan2}(\pm 0, x) = \begin{cases} \pm 0 & x > 0 \text{ or } x \text{ is } +0, \\[5mu] \pm \pi & x < 0 \text{ or } x \text{ is } -0. \end{cases}\end{split}\]

The sign of the result matches the sign of \(y\) in these zero cases. The equations describe the mathematical result, not an evaluation of \(y/x\) followed by atan(), which could overflow or underflow.