MySQL ATAN() Function

The ATAN() function calculates the arc tangent (inverse tangent) of one or two numeric values.


Syntax

ATAN(number)

or

ATAN(a, b)

Definition and Usage

  • The ATAN() function returns the arc tangent (inverse tangent) of a number or the result of dividing two numbers (a / b).
  • If one parameter (number) is provided, it returns the arc tangent of that value.
  • If two parameters (a, b) are provided, it calculates the arc tangent of the quotient a / b.

Parameter Values

Parameter Description
number A numeric value.
a, b Two numeric values to calculate ATAN(a/b).

Technical Details

  • Works in: From MySQL 4.0
  • Result:
    • If number is used, the result is in radians within the range [−π2,π2][- \frac{\pi}{2}, \frac{\pi}{2}].
    • If a, b are used, the result is in radians within the range [−π,π][- \pi, \pi].

Examples

Example 1: Arc tangent of a single value

SELECT ATAN(2.5);

Result:

1.1902899496825317

Example 2: Arc tangent of a negative value

SELECT ATAN(-0.8);

Result:

-0.6747409422235527

Example 3: Arc tangent of two values

SELECT ATAN(-0.8, 2);

Result:

-0.3805063771123649

Example 4: Arc tangent of 0

SELECT ATAN(0);

Result:

0

Usage Notes

  1. Radians to Degrees Conversion: Multiply the result by 180π\frac{180}{\pi} to convert to degrees:

    SELECT ATAN(2.5) * (180 / PI());
    

    Result in degrees:

    68.19859051364818
    
  2. Trigonometric Applications:

    • Use ATAN() for geometric calculations, such as finding angles in triangles.
    • The two-parameter version (ATAN(a, b)) is useful for determining the direction of a vector.
  3. Null Handling:

    • If the parameter(s) are NULL, the function returns NULL.

Example Query with Conversion

To get the arc tangent of several values in both radians and degrees:

SELECT 
    ATAN(2.5) AS Radians,
    ATAN(2.5) * (180 / PI()) AS Degrees;

Result:

Radians: 1.1902899496825317
Degrees: 68.19859051364818

Was this article helpful?