COS

COS is a SQL mathematical function that calculates the cosine of a specified angle. The angle must be in radians. It returns a value between -1 and 1.

COS(X)Here, X represents a numeric expression.

  • x: Represents the angle in radians for which the cosine value is to be calculated.

Example

SELECT COS(PI());

Output

-1.0

Explanation

The COS function in MySQL returns the cosine of a number. In the provided example, the number used is the mathematical constant PI. The cosine of PI, in mathematics, is -1, therefore, the output of the function is -1.0.

COS(float_expression)

  • float_expression: This parameter represents an expression of type float from which the SQL Server derives the cosine. The specified float expression should be from -1 to 1 because cos(x) is defined in these ranges. If NULL is inputted, the output will also be NULL.

Example

DECLARE @radian_value FLOAT;
SET @radian_value = PI()/3;
SELECT COS(@radian_value) as Cosine_Value;

Output

| Cosine_Value |
|---------------------|
| 0.500000011324464 |

Explanation

In the SQL code provided, COS() function is used to calculate cosine of the radian value. We first declare a variable and set it to PI()/3 which converts degree to radian. Finally, the COS() function is applied on this radian to get the cosine value. The result returns the cosine value of the radian. In SQL, COS() function returns the cosine of the specified radian value.

COS(n NUMBER) RETURN NUMBER;

  • n number: This is the numeric value, in degrees, for which the cosine is to be computed. The COS function will return the cosine of this given number.

Example

SELECT COS(1) FROM dual;

Output

0.54030230586814

Explanation

In the example above, the COS function, which computes the cosine of a number, is used to calculate the cosine of 1. The FROM dual clause is necessary in Oracle SQL to select from a dummy table. The result of COS(1) is 0.54030230586814.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.