In MySQL, the COS()
function returns the cosine of a given value, where the value is given in radians.
The cosine is the trigonometric function that is equal to the ratio of the side adjacent to an acute angle (in a right-angled triangle) to the hypotenuse.
Syntax
The syntax goes like this:
COS(X)
Where X
is the value for which you’d like the cosine returned.
Example 1 – Basic Usage
Here’s a basic example to demonstrate what COS()
returns for a given number.
SELECT COS(1);
Result:
+--------------------+ | COS(1) | +--------------------+ | 0.5403023058681398 | +--------------------+
Example 2 – Using PI
In this example, I get the cosine of π (pi). I do this by passing in the PI()
function as an argument.
SELECT COS(PI());
Result:
+-----------+ | COS(PI()) | +-----------+ | -1 | +-----------+