atan2

atan2(x1: array, x2: array, /) array

Calculates an implementation-dependent approximation of the inverse tangent of the quotient x1/x2, having domain [-infinity, +infinity] x [-infinity, +infinity] (where the x notation denotes the set of ordered pairs of elements (x1_i, x2_i)) and codomain [-π, +π], for each pair of elements (x1_i, x2_i) of the input arrays x1 and x2, respectively. Each element-wise result is expressed in radians.

The mathematical signs of x1_i and x2_i determine the quadrant of each element-wise result. The quadrant (i.e., branch) is chosen such that each element-wise result is the signed angle in radians between the ray ending at the origin and passing through the point (1,0) and the ray ending at the origin and passing through the point (x2_i, x1_i).

Note

Note the role reversal: the “y-coordinate” is the first function parameter; the “x-coordinate” is the second function parameter. The parameter order is intentional and traditional for the two-argument inverse tangent function where the y-coordinate argument is first and the x-coordinate argument is second.

By IEEE 754 convention, the inverse tangent of the quotient x1/x2 is defined for x2_i equal to positive or negative zero and for either or both of x1_i and x2_i equal to positive or negative infinity.

Special cases

For floating-point operands,

  • If either x1_i or x2_i is NaN, the result is NaN.

  • If x1_i is greater than 0 and x2_i is +0, the result is an implementation-dependent approximation to +π/2.

  • If x1_i is greater than 0 and x2_i is -0, the result is an implementation-dependent approximation to +π/2.

  • If x1_i is +0 and x2_i is greater than 0, the result is +0.

  • If x1_i is +0 and x2_i is +0, the result is +0.

  • If x1_i is +0 and x2_i is -0, the result is an implementation-dependent approximation to .

  • If x1_i is +0 and x2_i is less than 0, the result is an implementation-dependent approximation to .

  • If x1_i is -0 and x2_i is greater than 0, the result is -0.

  • If x1_i is -0 and x2_i is +0, the result is -0.

  • If x1_i is -0 and x2_i is -0, the result is an implementation-dependent approximation to .

  • If x1_i is -0 and x2_i is less than 0, the result is an implementation-dependent approximation to .

  • If x1_i is less than 0 and x2_i is +0, the result is an implementation-dependent approximation to -π/2.

  • If x1_i is less than 0 and x2_i is -0, the result is an implementation-dependent approximation to -π/2.

  • If x1_i is greater than 0, x1_i is a finite number, and x2_i is +infinity, the result is +0.

  • If x1_i is greater than 0, x1_i is a finite number, and x2_i is -infinity, the result is an implementation-dependent approximation to .

  • If x1_i is less than 0, x1_i is a finite number, and x2_i is +infinity, the result is -0.

  • If x1_i is less than 0, x1_i is a finite number, and x2_i is -infinity, the result is an implementation-dependent approximation to .

  • If x1_i is +infinity and x2_i is finite, the result is an implementation-dependent approximation to +π/2.

  • If x1_i is -infinity and x2_i is finite, the result is an implementation-dependent approximation to -π/2.

  • If x1_i is +infinity and x2_i is +infinity, the result is an implementation-dependent approximation to +π/4.

  • If x1_i is +infinity and x2_i is -infinity, the result is an implementation-dependent approximation to +3π/4.

  • If x1_i is -infinity and x2_i is +infinity, the result is an implementation-dependent approximation to -π/4.

  • If x1_i is -infinity and x2_i is -infinity, the result is an implementation-dependent approximation to -3π/4.

Parameters:
  • x1 (array) – input array corresponding to the y-coordinates. Should have a floating-point data type.

  • x2 (array) – input array corresponding to the x-coordinates. Must be compatible with x1 (see Broadcasting). Should have a floating-point data type.

Returns:

out (array) – an array containing the inverse tangent of the quotient x1/x2. The returned array must have a floating-point data type determined by Type Promotion Rules.