SQL Server COS() Function

The COS() function in SQL Server calculates the cosine of an angle. The input angle must be provided in radians.



COS(): Definition and Usage

The cosine function (cos) is a fundamental trigonometric function used extensively in mathematics, science, and engineering. In SQL Server, the COS() function allows you to easily incorporate cosine calculations into your queries. The input to the function is an angle expressed in radians, and the output is the cosine of that angle, which will be a value between -1 and 1.

Syntax

Syntax

COS(number)
      

Parameter Values

Parameter Description
number The angle in radians for which you want to calculate the cosine. This is required and must be a numeric value.

Examples

Calculating the Cosine of a Number

This example calculates the cosine of 2 radians.

Syntax

SELECT COS(2);
      
Output

-0.416146836547142
      

Calculating the Cosine of Pi

This example calculates the cosine of π (pi) radians which is -1.

Syntax

SELECT COS(PI());
      
Output

-1.00000000000000
      

**Note:** The output values are approximate due to the nature of floating-point arithmetic and may vary very slightly depending on your SQL Server version. The input to `COS()` is an angle in radians. To convert degrees to radians, use the `RADIANS()` function.