MySQL - COS() Function
The COS() function of MySQL calculates the trigonometric cosine value of numbered data.
The trigonometric cosine of an angle is defined as the ratio of the adjacent side of the said angle to the hypotenuse in a right-angled triangle.
This function accepts an integer value (in radians) as a parameter and returns the cosine value.
Syntax
Following is the syntax of MySQL COS() function −
COS(x);
Parameters
This function takes a numeric value representing an angle in radians as a parameter.
Return Value
This function returns the cosine of given angle.
Example
In the following query, we are using the COS() function to calculate the cosine of the value 8 −
SELECT COS(8) As Result;
Output
This will produce the following result −
| Result |
|---|
| -0.14550003380861354 |
Example
You can also pass pi() function as a value to this function as shown below. The value of PI() function is 3.14 −
SELECT COS(PI()) As Result;
Output
The output for the query above is produced as given below −
| Result |
|---|
| -1 |
Example
Following is another example of for COS() function −
SELECT COS(-16) As Result;
Output
This will produce the following result −
| Result |
|---|
| -0.9576594803233847 |
Example
The following query calculates the cosine of the value 0 −
SELECT COS(0) As Result;
Output
The output for the query above is produced as given below −
| Result |
|---|
| 1 |