Fact-checked by Grok 2 weeks ago

atan2

In and , the atan2 function, also known as the two-argument arctangent, computes the principal value of the argument of the x + iy, which corresponds to the counterclockwise \theta from the positive real axis to the point (x, y) in the Cartesian , with \theta = \tan^{-1}(y/x) adjusted for the correct based on the signs of x and y. Unlike the single-argument arctangent function \tan^{-1}(z), which maps to the (-\pi/2, \pi/2) and cannot distinguish quadrants, atan2(y, x) handles cases where x = 0 without and provides the full principal range (-\pi, \pi]. For example, atan2(0, 1) returns $0, atan2(1, 0) returns \pi/2, atan2(0, -1) returns \pi, and atan2(-1, 0) returns -\pi/2. The function's design ensures accurate angle computation across all four quadrants by examining the signs of both inputs: if x > 0, it uses \tan^{-1}(y/x); if x < 0 and y \geq 0, it adds \pi; if x < 0 and y < 0, it subtracts \pi; and for x = 0, it returns \pi/2 if y > 0, -\pi/2 if y < 0, and is undefined if both are zero. This quadrant-aware behavior makes atan2 essential for converting to polar form, where the angle \theta satisfies \cos \theta = x / r and \sin \theta = y / r with radius r = \sqrt{x^2 + y^2}. In complex analysis, it directly yields the phase or argument of z = x + iy, facilitating operations like logarithm and exponentiation in the complex plane. Introduced in early programming languages to support scientific computations, atan2 has become a standard in mathematical libraries, such as those in C, Fortran, and JavaScript, where it is implemented to return values in radians within the specified range, often with high precision for floating-point inputs. Its derivative and integral properties align with those of the arctangent, but its multi-quadrant capability extends its utility in fields like computer graphics for rotation calculations, robotics for orientation, and signal processing for phase detection.

Overview and Motivation

Purpose in Polar Coordinates

The atan2(y, x) function determines the angle θ from the positive x-axis to the point (x, y) in the Cartesian plane, satisfying tan(θ) = y/x while accounting for the correct quadrant based on the signs of y and x. This ensures an unambiguous computation of the polar angle, as the function returns values in the interval (-π, π], where the sign and magnitude reflect the position relative to the origin. Unlike the single-argument arctangent, which cannot distinguish between quadrants, atan2 resolves this by examining both coordinates, making it indispensable for transformations between and in computational tasks. This capability arose from the need in early computing to handle two-dimensional geometry without angle ambiguities, particularly in fields like engineering simulations and basic graphics where precise directional information was required. In the 1960s, as computers began tackling complex vector calculations, the limitations of standard trigonometric inverses became evident, prompting the development of a robust two-argument variant to support reliable polar coordinate conversions. The function was first implemented in the IBM compiler in 1961 as ATAN2, marking a key advancement in numerical libraries for handling principal arguments of complex numbers. For instance, atan2(1, 1) yields \pi/4 for a point in the first quadrant, while atan2(1, -1) yields $3\pi/4 for a point in the second quadrant, demonstrating quadrant-specific outputs.

Distinction from Single-Argument Arctangent

The single-argument arctangent function, denoted as \operatorname{atan}(z), computes the principal value of the inverse tangent, returning angles in the open interval (-\pi/2, \pi/2). This restricted range ensures a unique principal branch but limits its utility for determining angles across the full Cartesian plane, as it cannot distinguish between points in different quadrants when the input is derived from a ratio such as y/x. Specifically, computing \operatorname{atan}(y/x) discards the sign of x, leading to incorrect angle assignments for points where x < 0; for instance, \operatorname{atan}(1/1) = \pi/4 correctly identifies the angle in the first quadrant, but \operatorname{atan}(1/(-1)) = \operatorname{atan}(-1) = -\pi/4 erroneously places the point (-1, 1) in the fourth quadrant rather than the correct second quadrant at $3\pi/4. This approach also introduces discontinuities along the negative x-axis and at the origin, where the ratio y/x becomes undefined or ambiguous, complicating applications like polar coordinate conversions. In contrast, the two-argument \operatorname{atan2}(y, x) function resolves these issues by explicitly considering the signs of both y and x to select the appropriate branch of the multi-valued arctangent, yielding the principal in the interval (-\pi, \pi]. This quadrant-aware computation ensures continuous representation over the entire plane, excluding the branch cut along the negative real axis; for the example above, \operatorname{atan2}(1, -1) = 3\pi/4, accurately reflecting the second-quadrant position. By avoiding the ratio y/x altogether and handling special cases like x = 0 directly (e.g., returning \pi/2 if y > 0 and x = 0), \operatorname{atan2} provides a robust solution for full-plane angle determination without the principal value limitations that plague the single-argument form.

Mathematical Definition

Formal Definition and Notation

The two-argument arctangent function, denoted as \operatorname{atan2}(y, x), is formally defined as the principal value of the argument of the x + iy, where i is the . Specifically, \operatorname{atan2}(y, x) = \arg(x + iy), with the argument taken in the principal branch (-\pi, \pi]. This definition ensures the function returns the angle \theta such that \cos \theta = x / r and \sin \theta = y / r, where r = \sqrt{x^2 + y^2} is the , while correctly accounting for the quadrant based on the of x and y. Equivalently, \operatorname{atan2}(y, x) can be expressed using the principal branch of the as the imaginary part: \operatorname{atan2}(y, x) = \Im(\log(x + iy)), where \log denotes the principal logarithm with imaginary part in (-\pi, \pi]. The explicit formula for \operatorname{atan2}(y, x) is given by: \begin{align*} \operatorname{atan2}(y, x) &= \begin{cases} \atan\left(\frac{y}{x}\right) & \text{if } x > 0, \\ \atan\left(\frac{y}{x}\right) + \pi & \text{if } x < 0 \text{ and } y \geq 0, \\ \atan\left(\frac{y}{x}\right) - \pi & \text{if } x < 0 \text{ and } y < 0, \\ \frac{\pi}{2} & \text{if } x = 0 \text{ and } y > 0, \\ -\frac{\pi}{2} & \text{if } x = 0 \text{ and } y < 0. \end{cases} \end{align*} When x = y = 0, the value is typically defined as 0 in many implementations, though mathematically undefined. The standard notation \operatorname{atan2}(y, x) places the ordinate y first and the abscissa x second, reflecting the coordinates of the point (x, y) in the plane; this convention originated in early programming languages like Fortran and is adopted in standards such as ISO/IEC 9899 for C. While some specialized contexts or variations may swap the argument order to \operatorname{atan2}(x, y), the y-x order remains the widely accepted norm in mathematics and computing.

Domain, Range, and Quadrant Handling

The two-argument arctangent function, denoted as \operatorname{atan2}(y, x), is defined over the domain of all pairs of real numbers y \in \mathbb{R} and x \in \mathbb{R}, excluding the special case where both y = 0 and x = 0, as this point corresponds to the origin where no unique angle is defined mathematically. In standards like POSIX, no domain error occurs when both arguments are zero, with the return value being implementation-defined—commonly 0 to maintain continuity in numerical contexts. This handling avoids direct division by zero in the underlying computation and ensures robustness in applications like polar coordinate conversions. The range of \operatorname{atan2}(y, x) is the half-open interval (-\pi, \pi], which assigns a unique principal value to the angle \theta for every nonzero point (x, y) in the plane, corresponding to the counterclockwise angle from the positive x-axis to the ray from the origin through that point. This interval choice excludes redundancy while covering all possible directions, with the boundary at \pi and -\pi identified except along the branch cut. In floating-point implementations, the value -\pi may be returned for atan2 with negative for y and x < 0. The standard ensures that \operatorname{atan2}(y, x) = [0](/page/0) when y = [0](/page/0) and x > 0, \operatorname{atan2}(y, x) = \pi (or -\pi depending on the of for y) when y = [0](/page/0) and x < 0, \operatorname{atan2}(y, 0) = \pi/2 when y > 0, and \operatorname{atan2}(y, 0) = -\pi/2 when y < 0. Quadrant determination relies on the signs of x and y to select the appropriate sector without computing the ratio y/x directly when x = 0, thus preventing division-by-zero errors. Specifically, a positive x places the angle in the right half-plane (first or fourth quadrant), refined by the sign of y: positive y yields [0, \pi/2) and negative y yields (-\pi/2, 0]. A negative x shifts to the left half-plane (second or third quadrant), adding or subtracting \pi to the arctangent of the absolute ratio based on y's sign: positive y gives (\pi/2, \pi] and negative y gives [-\pi, -\pi/2). Zero cases are resolved as noted above to maintain the full-circle coverage. A notable feature is the discontinuity along the negative x-axis (where y = 0 and x < 0), serving as the branch cut: as y approaches 0 from the positive side, \operatorname{atan2}(y, x) approaches \pi, while from the negative side it approaches -\pi, creating a jump of $2\pi that reflects the multi-valued nature of angles but ensures a single-valued principal branch within the specified range. This cut is conventional for in complex analysis and aligns with the function's role in computing arguments of complex numbers x + iy.

Computation and Algorithms

Core Algorithm

The core algorithm for computing \atan2(y, x) in standard mathematical libraries involves first handling the case where x = 0, returning \pi/2 if y > 0 or -\pi/2 if y < 0 (with y = 0 addressed separately but excluded here as per focus on general flow). For x \neq 0, the process computes the absolute ratio r = |y| / |x|, evaluates \theta = \atan(r) using an efficient arctangent approximation, and then adjusts \theta based on the quadrant determined by the signs of x and y: if x > 0 and y \geq 0, return \theta; if x > 0 and y < 0, return -\theta; if x < 0 and y \geq 0, return \pi - \theta; if x < 0 and y < 0, return -\pi + \theta. This quadrant adjustment ensures the result lies in (-\pi, \pi] while correctly capturing the angle's direction. The \atan(r) step relies on approximations to balance accuracy and speed, as direct table lookups or infinite series are impractical for floating-point hardware. Common methods include truncated Taylor series expansions around 0, such as \atan(r) \approx r - r^3/3 + r^5/5 for small r, combined with range reduction techniques for larger inputs. For hardware implementations, the CORDIC (COordinate Rotation DIgital Computer) algorithm is widely used, iteratively rotating a vector (x, y) through additions and shifts to converge on the angle, requiring no multipliers and achieving high precision after n iterations proportional to the bit width. In pseudocode, a basic software implementation follows this structure:
function atan2(y, x):
    if x == 0 and y == 0:
        return 0
    if x == 0:
        if y > 0:
            return π/2
        else:
            return -π/2
    r = abs(y) / abs(x)
    theta = atan(r)  // using approximation
    if x > 0:
        if y >= 0:
            return theta
        else:
            return -theta
    else:
        if y >= 0:
            return π - theta
        else:
            return -π + theta
This approach executes in constant time O(1) on modern processors with hardware support for and arctangent, typically completing in a few cycles via optimized routines.

Special Cases and Edge Handling

One notable special case in the computation of atan2(y, x) occurs when both y = 0 and x = 0, corresponding to the in the , where is mathematically . Implementations typically return 0 in this scenario to provide a consistent result without raising an exception, aligning with the standard, which does not treat this as a domain error and specifies a return value of 0. This convention is widely adopted in numerical to ensure predictable behavior, though the exact sign (positive or negative ) may depend on the signs of the inputs per rules. For inputs involving NaN, atan2 propagates the NaN if either y or x is NaN, following the recommendation for quiet NaN propagation in arithmetic and mathematical operations, ensuring that invalid inputs yield invalid results without unnecessary exceptions. To handle overflow and underflow risks during ratio computation, robust implementations scale the arguments by comparing their magnitudes: if |x| ≥ |y|, compute the ratio z = |y| / |x| and adjust the angle accordingly; otherwise, compute z = |x| / |y| and add or subtract π/2 based on the . This approach confines the argument to the single-argument atan to [0, 1], preventing from large ratios (e.g., when |x| is near zero and |y| is large) and underflow from very small ratios, while maintaining accuracy through scaled computations. Numerical stability near the coordinate axes is enhanced by alternative formulations that avoid subtractive cancellation. For instance, when |y| ≫ |x|, atan2(y, x) ≈ sgn(y) * (π/2 - atan(|x| / |y|)), where the small argument to atan ensures precise without loss of significant digits from subtracting two nearly equal large values (as would occur in π/2 - atan(|y| / |x|)). Additionally, fused multiply-add (FMA) operations can be employed to compute ratios like y / x more accurately by reducing errors in intermediate multiplications and additions.

Calculus and Properties

Derivative

The function \operatorname{atan2}(y, x) is differentiable everywhere except at the origin (0, 0), where it is undefined. The partial derivatives are given by \frac{\partial}{\partial x} \operatorname{atan2}(y, x) = -\frac{y}{x^2 + y^2}, \frac{\partial}{\partial y} \operatorname{atan2}(y, x) = \frac{x}{x^2 + y^2}. These expressions hold for all (x, y) \neq (0, 0), reflecting the smooth behavior of the function away from the origin and the branch cut along the negative real axis. To derive these, consider \theta = \operatorname{atan2}(y, x), which satisfies \tan \theta = y / x in the appropriate . Differentiating both sides implicitly with respect to the variables yields \sec^2 \theta \, d\theta = (x \, dy - y \, dx) / x^2. Since \sec^2 \theta = 1 + \tan^2 \theta = (x^2 + y^2) / x^2, substituting gives the total differential d\theta = \frac{x \, dy - y \, dx}{x^2 + y^2}. This form is obtained via standard implicit differentiation techniques for the inverse tangent relation adjusted for two arguments. The total differential is particularly useful in optimization contexts, such as gradient-based methods in or where angular coordinates are involved, as it provides the infinitesimal change in for small perturbations in .

Sum and Difference Identities

The sum identity for the two-argument arctangent function arises from the standard trigonometric formulas, where \alpha + \beta can be expressed using \operatorname{atan2}(\sin(\alpha + \beta), \cos(\alpha + \beta)). Specifically, \sin(\alpha + \beta) = \sin \alpha \cos \beta + \cos \alpha \sin \beta, \cos(\alpha + \beta) = \cos \alpha \cos \beta - \sin \alpha \sin \beta. Thus, \operatorname{atan2}(\sin(\alpha + \beta), \cos(\alpha + \beta)) = \operatorname{atan2}(\sin \alpha \cos \beta + \cos \alpha \sin \beta, \cos \alpha \cos \beta - \sin \alpha \sin \beta) = \alpha + \beta \pmod{2\pi}, with the result adjusted to the principal range (-\pi, \pi]. The difference identity follows analogously from the trigonometric subtraction formulas: \sin(\alpha - \beta) = \sin \alpha \cos \beta - \cos \alpha \sin \beta, \cos(\alpha - \beta) = \cos \alpha \cos \beta + \sin \alpha \sin \beta. Therefore, \operatorname{atan2}(\sin(\alpha - \beta), \cos(\alpha - \beta)) = \operatorname{atan2}(\sin \alpha \cos \beta - \cos \alpha \sin \beta, \cos \alpha \cos \beta + \sin \alpha \sin \beta) = \alpha - \beta \pmod{2\pi}, again normalized to the range (-\pi, \pi]. A more general addition formula for combining two angles directly from their Cartesian representations leverages the property of complex arguments, where \theta_1 = \operatorname{atan2}(y_1, x_1) and \theta_2 = \operatorname{atan2}(y_2, x_2) correspond to the arguments of the numbers z_1 = x_1 + i y_1 and z_2 = x_2 + i y_2. The sum \theta_1 + \theta_2 is the argument of the product z_1 z_2: z_1 z_2 = (x_1 x_2 - y_1 y_2) + i (x_1 y_2 + y_1 x_2), so \operatorname{atan2}(y_1, x_1) + \operatorname{atan2}(y_2, x_2) = \operatorname{atan2}(x_1 y_2 + y_1 x_2, x_1 x_2 - y_1 y_2) \pmod{2\pi}, with wrapping to ensure the result lies in (-\pi, \pi]; if the computed angle exceeds \pi, subtract $2\pi, or if below -\pi, add $2\pi. The difference formula is obtained by replacing the second angle with its negative, equivalent to conjugating z_2. These identities find applications in computing composite rotations, such as multiplying rotation matrices, where the total angle is the sum of individual angles derived via \operatorname{atan2} from vector components. They are also used in vector angle computations, for instance, to find the direction of the resultant vector from two vectors by treating them as complex numbers and applying the product rule.

Visual and Geometric Interpretations

Illustrations of Quadrant Behavior

The behavior of the atan2(y, x) function across the four quadrants is commonly illustrated using a diagram of the unit circle divided into quadrants, with radial lines from the origin to representative points in each sector labeled by their corresponding angle outputs. In the first quadrant (x > 0, y > 0), angles range from 0 to π/2 radians; in the second quadrant (x < 0, y > 0), from π/2 to π; in the third (x < 0, y < 0), from -π to -π/2; and in the fourth (x > 0, y < 0), from -π/2 to 0. The branch cut of atan2 is placed along the negative x-axis, where the function value jumps discontinuously from π (approached from above) to -π (approached from below) as a point crosses this line counterclockwise, ensuring the output remains within the principal range (-π, π]. Visual aids such as 3D surface plots or color-coded heatmaps of over the Cartesian plane highlight the resulting sawtooth pattern across the plane, where in the right half-plane (x > 0) the angle increases smoothly from -π/2 to π/2 as y increases from negative to positive values, and in the left half-plane (x < 0) from π/2 to π as y increases from 0 to positive infinity and from -π to -π/2 as y increases from negative infinity to 0, with the discontinuity manifesting as a sharp drop along the branch cut. A concrete example is the point (3, 4) in the first quadrant, where atan2(4, 3) yields approximately 0.927 radians, corresponding to the angle whose tangent is 4/3.

Polar Coordinate Applications

The conversion from Cartesian coordinates (x, y) to polar coordinates (r, \theta) relies on the atan2 function to determine the polar angle \theta accurately across all quadrants. The radial distance r is computed as r = \sqrt{x^2 + y^2}, while the angle is given by \theta = \atan2(y, x), where \theta ranges from -\pi to \pi. This formulation ensures the correct orientation relative to the positive x-axis, with the atan2 function handling the signs of x and y separately to avoid ambiguities inherent in the standard arctangent. In computer graphics, atan2 is essential for computing rotation angles and direction vectors, particularly in 2D rendering and animation. For instance, to orient a sprite or object toward a target point, the angle is derived from the difference in coordinates using \atan2(\Delta y, \Delta x), enabling precise aiming in games or simulating angular movement in simulations. This application is common in inverse kinematics for character limbs, where joint rotations are calculated to align endpoints with desired positions, ensuring smooth and quadrant-correct orientations without manual sign adjustments. In physics, atan2 facilitates angle computations in projectile motion and orbital mechanics by providing the direction of velocity vectors or position angles. For projectile trajectories, the launch or impact angle can be found using \atan2(v_y, v_x) on velocity components, accurately capturing the direction even when crossing axes. Similarly, in orbital simulations, atan2 converts position vectors to polar angles for or attitude determination, supporting precise modeling of satellite paths around celestial bodies. A key advantage of atan2 in these applications is its ability to prevent errors such as sign flips in velocity directions, which occur with the standard atan function due to its limited range of -\pi/2 to \pi/2. By considering the signs of both arguments, atan2 delivers the full $2\pi range, ensuring consistent angular representations in dynamic systems like rotating objects or orbiting particles.

Field-Specific Conventions

Standard Mathematical Usage

In complex analysis, the two-argument arctangent function, denoted as \operatorname{atan2}(y, x), computes the principal argument of the complex number z = x + iy, where x and y are real numbers and (x, y) \neq (0, 0). This principal value, often symbolized as \operatorname{Arg}(z), is defined to lie within the interval (-\pi, \pi], providing a unique angle \theta such that z = |z| e^{i\theta}. The function distinguishes the correct quadrant based on the signs of x and y, ensuring \operatorname{atan2}(y, x) = \theta where \cos \theta = x / |z| and \sin \theta = y / |z|. The argument function \operatorname{arg}(z) is inherently multi-valued, with values differing by integer multiples of $2\pi, reflecting the periodic nature of angles around the origin. \operatorname{atan2}(y, x) selects the principal branch of this multi-valued function, analogous to choosing the principal branch for the inverse tangent in the context of complex logarithms, where \log z = \ln |z| + i \operatorname{arg}(z). This branch cut is conventionally placed along the negative real axis, making \operatorname{atan2} the standard tool for unambiguous angle computation in mathematical contexts. The output of \operatorname{atan2}(y, x) is expressed in radians, aligning with the primary unit of angular measure in pure mathematics and complex analysis. While conversions to degrees can be performed by multiplying the result by $180/\pi, radians ensure consistency with exponential forms and trigonometric identities fundamental to the field. Theoretically, \operatorname{atan2}(y, x) is continuous everywhere in the complex plane except across the branch cut on the negative real axis, where it exhibits a discontinuity of $2\pi. The full argument function is periodic with period $2\pi, meaning \operatorname{arg}(z e^{i 2\pi k}) = \operatorname{arg}(z) + 2\pi k for any integer k, but the principal branch restricts values to avoid redundancy while preserving analytic properties in regions excluding the cut. In navigation and related fields, adaptations of the atan2 function address varying coordinate conventions to compute directions like bearings and azimuths. The standard atan2(y, x), with y as the north component and x as the east component, follows the east-counterclockwise convention, measuring angles counterclockwise from the positive x-axis (east). This aligns with pure mathematical norms but requires modification for practical applications where directions are referenced from north or south. A common adaptation is the north-clockwise convention, used in aviation bearings and GPS systems, where angles are measured clockwise from north, typically in the range 0° to 360°. Here, the bearing θ is computed as θ = \mod(360^\circ, \deg(\atan2(\Delta e, \Delta n))), where \Delta e is the easting difference (sin \Delta\lambda \cos \phi_2) and \Delta n is the northing difference (\cos \phi_1 \sin \phi_2 - \sin \phi_1 \cos \phi_2 \cos \Delta\lambda), with \phi denoting latitude and \lambda longitude. This adjustment effectively swaps and signs the arguments relative to the standard to yield clockwise angles from north; for instance, an eastward direction returns 90°, southward 180°. In aviation, this facilitates true course calculations between waypoints, while in GPS, it determines vehicle headings for route guidance. In GPS applications, atan2-derived headings provide real-time direction from current position to destination, essential for turn-by-turn navigation, with the north-clockwise output directly informing device displays. Historically, celestial navigation employed analogous trigonometric methods for azimuth computation from star observations, predating digital tools; modern implementations use atan2 to automate these, as in calculating solar or stellar azimuths from altitude and sidereal time for position fixes in astronomy and maritime use.

Implementations in Software

Common Programming Languages

In C and C++, the atan2 function is provided in the <cmath> header as double atan2(double y, double x), computing the principal value of the arc tangent of the ratio y/x while using the signs of both arguments to determine the correct , returning a value in the range (- \pi, \pi] in radians. This implementation adheres to the standard for , handling special cases such as inputs (returning ), infinite values (returning appropriate signed \pi/2 or -\pi/2 based on signs), and zero cases (e.g., atan2(0, 0) returns 0). Python's standard library includes math.atan2(y, x) in the math module, mirroring the C/C++ behavior by returning the arc tangent in radians within (- \pi, \pi], with quadrant determination based on input signs, and similarly compliant with for (returns ) and infinity cases. For array processing, offers a vectorized numpy.arctan2(x1, x2) function that applies the operation element-wise to arrays or scalars, preserving the same range and special value handling while enabling efficient computation on multidimensional data. In , the global Math object provides Math.atan2(y, x), which returns the counterclockwise angle in radians from the positive x-axis to the point (x, y), ranging from -\pi to \pi, with the function distinguishing between positive and negative zero (e.g., Math.atan2(0, 0) returns 0, while Math.atan2(-0, 0) returns -0). It returns for NaN inputs or invalid combinations like with zero numerator in certain edge cases, aligning with specifications for numeric operations. Java's java.lang.Math defines static double atan2(double y, double x), delivering the two-argument arctangent with results precise to the full range of -precision floating-point representation, returning values in (-\pi, \pi] and handling special values per semantics, such as 0 for atan2(0.0, 0.0) and \pi for atan2(0.0, -0.0).

Library-Specific Behaviors

Most modern libraries adhering to the IEEE 754-2008 standard for floating-point arithmetic return 0 for atan2(0, 0), with the sign of the result matching the sign of the y argument in cases involving signed zeros, ensuring no domain error occurs. These implementations also preserve signed zero distinctions, such as returning -0 when y is -0 and x is positive, to maintain consistency with the standard's rules for operations near the origin. This compliance became more widespread after the 2008 revision, which clarified behaviors for indeterminate forms like (0, 0). In contrast, older Fortran implementations, such as those from Fortran 77, treat atan2(0, 0) as undefined or erroneous, potentially returning an arbitrary value or signaling an error, as the language standard did not specify a precise outcome. MATLAB's atan2 function returns 0 for atan2(0, 0), aligning with a simplified convention, but it deviates from IEEE 754 in signed zero cases—for instance, atan2(0, -0) yields 0 rather than π. Vectorized extensions enhance efficiency for array-based computations: and SciPy's arctan2 leverages universal function (ufunc) broadcasting to apply the operation element-wise across arrays of compatible shapes, enabling seamless handling of multi-dimensional inputs without explicit loops. On GPUs, NVIDIA's math API exposes atan2 as a __device__ function, optimized for parallel execution across thousands of threads, with accuracy up to 2 units in the last place (ULP) for double precision. Post-2020 updates in emerging standards address previously underdocumented edge cases: WebAssembly's integration with JavaScript's Math.atan2 ensures precise propagation, returning values like -0 for appropriate inputs to match semantics in browser and standalone environments. Similarly, Rust's f64::atan2 delivers IEEE-compliant results, including 0 for (0, 0) and correct quadrant selection for signed zeros, benefiting with high-performance numerical code. Traditional references often overlook these refinements, focusing instead on pre-2010 behaviors.

References

  1. [1]
    Inverse Tangent -- from Wolfram MathWorld
    The inverse tangent, denoted as tan^(-1)z or arctanz, is the inverse function of the tangent and is a multivalued function.Missing: two- | Show results with:two-
  2. [2]
    atan2 - Four-quadrant inverse tangent - MATLAB - MathWorks
    The `atan2` function returns the four-quadrant inverse tangent of Y and X, returning values in the interval [–π, π].
  3. [3]
    ATAN2 (The GNU Fortran Compiler)
    ATAN2(Y, X) computes the principal value of the argument function of the complex number X + i Y. This function can be used to transform from Cartesian into ...Missing: origin history
  4. [4]
    DLMF: §4.23 Inverse Trigonometric Functions ‣ Trigonometric Functions ‣ Chapter 4 Elementary Functions
    ### Summary of Principal Value of Arctan and Related Details from §4.23
  5. [5]
    atan
    - **Description**: The `atan`, `atanf`, and `atanl` functions compute the principal value of the arc tangent of their argument `x`. Applications should set `errno` to zero and call `feclearexcept(FE_ALL_EXCEPT)` before use to check for errors.
  6. [6]
    atan2
    The function below uses atan2() to convert a 2d vector expressed in cartesian coordinates (x,y) to the polar coordinates (rho,theta). There are other ways ...
  7. [7]
    [PDF] Complex Analysis with Applications Princeton University MAT330 ...
    Jan 27, 2023 · arg (x + iy) ≡ atan2 (y, x)+2πn. (n ∈ Z) . The principal value of ... ∂x Logα (x + iy) = ∂x log p x2 + y2. + i∂x arctanα y x. = 1 px2 ...
  8. [8]
    WorksheetFunction.Atan2 method (Excel) - Microsoft Learn
    Sep 12, 2021 · Where y < 0, x < 0 ATAN2(x,y) = ATAN(y/x) - PI(). Where y > 0, x = 0 ATAN2(x,y) = PI()/2. Where y < 0, x = 0 ATAN2(x,y) = -PI()/2. If both x ...
  9. [9]
    atan2.c\math\src - musl - musl - an implementation of the standard ...
    atan2(y,x) * Method : * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). * 2. Reduce x to positive by (if x and y are unexceptional): * ARG (x+iy) ...Missing: fdlibm | Show results with:fdlibm
  10. [10]
    [PDF] Efficient Approximations for the Arctangent Function
    Approximations to the arctangent function can be obtained using second- and third-order polynomials and simple rational functions. Lagrange interpolation-based ...
  11. [11]
    [PDF] Hardware implementations of fixed-point Atan2 - Hal-Inria
    Dec 4, 2014 · Abstract—The atan2 function computes the polar angle arctan(x/y) of a point given by its cartesian coordinates.Missing: origin history
  12. [12]
    [PDF] ISO/IEC 9899:1999(E) -- Programming Languages -- C
    ... definition that acquires a value on entry to the function, or an identifier ... atan2 functions. Synopsis. 1. #include <math.h> double atan2(double y ...
  13. [13]
    e_atan2.c - The Netlib
    ... Special cases: * * ATAN2((anything), NaN ) is NaN; * ATAN2(NAN , (anything) ) is NaN; * ATAN2(+-0, +(anything but NaN)) is +-0 ; * ATAN2(+-0, -(anything but ...Missing: implementation | Show results with:implementation
  14. [14]
    [PDF] Finding the Center of a Phyllotactic Pattern - - Clark Science Center
    atan2(yj − y0,xj − x0). ∂θj. ∂y0. = ∂. ∂y0 atan2(yj − y0,xj − x0). We now need the partial derivatives of atan2. For x 6= 0 they can be computed by ...
  15. [15]
    Complex Argument -- from Wolfram MathWorld
    The complex argument is a real number, also called the phase, that is the counterclockwise angle from the positive real axis.
  16. [16]
  17. [17]
  18. [18]
    [PDF] Lecture 5: Forward and Inverse Kinematics; Learning Styles
    Oct 20, 2024 · >> atan2(-6,-3) * 180/pi ans ... remember best what they see--pictures, diagrams, flow charts, time lines, films, and demonstrations.<|control11|><|separator|>
  19. [19]
    Positions and coordinates
    An alternative is to use the atan2 function, which takes x and y as separate arguments and correctly handles the conversion to θ in any quadrant.
  20. [20]
    [PDF] Inverse Kinematics . . .
    Computer Graphics. 2. Inverse Kinematics. Forward Kinematics solves the problem ... θ* = atan2( Y*-Y2, X*-X2 ); θ = atan2( Y3-Y2 , X3-X2 );. Δθ2 = θ* - θ. Use the ...
  21. [21]
    Pointing towards movement (article) | Khan Academy
    To point towards movement, rotate based on the velocity vector. Use `atan2()` or `PVector.heading()` to calculate the angle.
  22. [22]
    [PDF] Physics 2210 Fall 2015
    Sep 2, 2015 · (%i1) /* The bullet travels according to projectile motion: constant ... (%i25) phi_g1: atan2(vgy1, vgx1)*180/%pi, numer;. (%o25).
  23. [23]
    [PDF] NASA Computational Case Study Modeling Planetary Magnetic and ...
    Most computer programming languages include a special built-in function to handle this case, usually called something like atan2(y,x). ... Introduction to Space ...
  24. [24]
    [PDF] 7. Complex numbers - MIT Mathematics
    This special θ is called the principal value of the argument, and is denoted in various ways: θ = Arg z = Arg[z]. Mathematica. = ArcTan[x,y]. Mathematica. = ...
  25. [25]
    [PDF] Functions of a Complex Variable (Zill & Wright Chapter 17)
    Sep 22, 2011 · arg z = atan2(y, x) + n2π n ∈ Z. (3.67). This means the ... The principal value just comes from taking the principal value of the argument:.
  26. [26]
    [PDF] 18.04 Complex analysis with applications - MIT Mathematics
    The argument will be continuous except for a jump by 2π when z crosses the branch cut. 3.3.3 The principal branch of arg(z). Branch (ii) in the previous ...
  27. [27]
  28. [28]
    Calculate distance and bearing between two Latitude/Longitude ...
    Bearing ; Formula: θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ ) ; where: φ1,λ1 is the start point, φ2,λ2 the end point (Δλ is the ...Missing: systems | Show results with:systems
  29. [29]
    Aviation Formulary V1.47
    True course is defined as usual, as the angle between the course line and the local meridian measured clockwise. The first important fact to realise is that in ...
  30. [30]
    [PDF] Survey Computations | UNSW Sydney
    Detail surveys with Total Stations and CAD. Data upload and download. Feature codes. 6. Detail Surveys and CoGo in CAD. 7. Cadastral calculations.<|separator|>
  31. [31]
    Computing Altitude and Azimuth from Greenwich Apparent Sidereal ...
    When finding the azimuth, the double-argument arctangent function (such as atan2 in Fortran or C) should be used with the numerator and denominator above ...
  32. [32]
    [PDF] Celestial Navigation - Hughes 38 Sailing
    Calculating the time azimuth is more convenient with the arctan2 (= atan2) function. The latter is part of many programming languages and spreadsheet ...
  33. [33]
    math — Mathematical functions — Python 3.14.0 documentation
    The point of atan2() is that the signs of both inputs are known to it, so it can compute the correct quadrant for the angle. For example, atan(1) and atan2(1, ...
  34. [34]
    Math.atan2() - JavaScript - MDN Web Docs
    Jul 10, 2025 · Math.atan2() returns the angle in radians between the positive x-axis and the ray from (0, 0) to (x, y), counterclockwise, with y first.
  35. [35]
  36. [36]
    std::atan2, std::atan2f, std::atan2l - cppreference.com
    ### Summary of `std::atan2` Behavior When Both Arguments Are Zero (IEEE 754)
  37. [37]