Thursday, December 26, 2024

SQL Server ACOS() Function

 The ACOS() function in SQL Server is a mathematical function that returns the arccosine (inverse cosine) of a given number. The result is expressed in radians.

Syntax:

ACOS(float_expression)
  • float_expression: A numeric expression representing a cosine value. The input must be in the range [-1, 1].

Return Type:

  • Returns a float value representing the angle in radians.

Example:

SELECT ACOS(1) AS Arccosine1, 
       ACOS(0.5) AS Arccosine05,
       ACOS(-1) AS ArccosineMinus1;

Output:

Arccosine1 Arccosine05 ArccosineMinus1
0.0 1.04719755 3.14159265

Notes:

  1. The ACOS() function is useful in trigonometric calculations and geometry-related queries.
  2. If the input value is outside the range [-1, 1], SQL Server will raise an error because the arccosine is undefined for such values.

Conversion to Degrees:

If you want the result in degrees instead of radians, you can use the formula:

DEGREES(ACOS(float_expression))

Example in Degrees:

SELECT DEGREES(ACOS(0.5)) AS ArccosineInDegrees;

This will return 60.0 as the result.

No comments:

Post a Comment