Skip to main content
Use the atan2 function in APL to compute the angle, in radians, between the positive x-axis and the point (y, x). Unlike atan, which takes a single ratio, atan2 takes separate y and x components, which avoids division-by-zero issues and preserves the correct quadrant information. atan2 is useful when you have two independent counts or values and want to express their ratio as an angle. For example, you can use atan2 to encode the balance between error count and success count as a direction vector, or to analyze the ratio of two traffic volumes.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, atan2(y, x) is available in the eval command with the same argument order and semantics.
| eval angle = atan2(errors, successes)
In ANSI SQL, the function is typically named ATN2(y, x) in SQL Server or ATAN2(y, x) in PostgreSQL. The argument order (y first, then x) is the same as in APL.
SELECT ATN2(errors, successes) AS angle FROM logs

Usage

Syntax

atan2(y, x)

Parameters

NameTypeRequiredDescription
yrealYesThe y-coordinate of the point (numerator).
xrealYesThe x-coordinate of the point (denominator).

Returns

The angle in radians between the positive x-axis and the point (y, x), in the range (-π, π].

Example

Use atan2 to compute the angle between the positive x-axis and the point (x, y). Query
print result = atan2(1, 1)
Run in Playground Output
result
0.7854
  • atan: Returns the arc tangent from a single ratio. Use it when you have a pre-computed ratio instead of separate y and x components.
  • asin: Returns the arc sine. Use it when the input maps to a sine value in [-1, 1].
  • acos: Returns the arc cosine. Use it when the input maps to a cosine value in [-1, 1].
  • tan: Returns the tangent. Use it to apply the forward transformation before using atan2 as the inverse.
  • degrees: Converts radians to degrees. Use it if you prefer the atan2 result in degrees.