SQL Tutorial SQL Advanced SQL Database SQL References

MySQL COS() Function

The MySQL COS() function returns trigonometric cosine of an angle (angle should be in radians).




x Required. Specify the angle in radian.

Return Value

Returns the trigonometric cosine of an angle.

Example 1:

The example below shows the usage of COS() function.

mysql> SELECT COS(0);
Result: 1

mysql> SELECT COS(1);
Result: 0.5403023058681398

mysql> SELECT COS(-1);
Result: 0.5403023058681398

mysql> SELECT COS(2);
Result: -0.4161468365471424

mysql> SELECT COS(-2);
Result: -0.4161468365471424

mysql> SELECT COS(PI());
Result: -1

Example 2:

Consider a database table called Sample with the following records:

Data 1-10
Data 2-5
Data 30
Data 45
Data 510

The query given below can be used to calculate the trigonometric cosine value of column x.

SELECT *, COS(x) AS COS_Value FROM Sample;

This will produce the result as shown below:

Data 1-10-0.8390715290764524
Data 2-50.28366218546322625
Data 301
Data 450.28366218546322625
Data 510-0.8390715290764524

❮ MySQL Functions