SQL Server ATN2() Function

The ATN2() function in SQL Server calculates the arctangent (inverse tangent) of two numbers. The arctangent is the angle whose tangent is the ratio of the two input numbers. The result is an angle, expressed in radians.



ATN2(): Definition and Usage

ATN2() is particularly useful when working with Cartesian coordinates (x, y) to determine the angle between the positive x-axis and the line segment from the origin (0,0) to the point (x, y). The function considers the signs of both inputs to determine the correct quadrant for the angle. The returned angle is in radians.

Syntax

Syntax

ATN2(a, b)
      

Parameter Values

Parameter Description
a The y-coordinate (a numeric value). This is required.
b The x-coordinate (a numeric value). This is required.

Examples

Calculating the Arctangent of Two Values

This example calculates the arctangent of 0.5 (0.5 / 1).

Syntax

SELECT ATN2(0.50, 1);
      
Output

0.463647609000806
      

Calculating the Arctangent of Different Values

This example calculates the arctangent of -0.4 (-0.8 / 2).

Syntax

SELECT ATN2(-0.8, 2);
      
Output

-0.38050637711219
      

**Note:** The output values are approximate and are expressed in radians. The precise value might vary slightly depending on your SQL Server version. If both `a` and `b` are 0, you will get an error.