Open In App

SIN() and COS() Function in MySQL

Last Updated : 18 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

1. SIN() Function : SIN() function in MySQL is used to return the sine of any given number X, where X is given in radians. Syntax :

SIN(X)

Parameter : Required. X : A number whose sine value we want to calculate. It is given in radian. Returns : It returns the sine of given number x. Example-1 : Sine of 0 using SIN() function.

SELECT SIN(0) AS Sin_Val;

Output :

Sin_Val
0

Example-2 : Sine of 90 degree i.e 1.5707963267948966 radian using SIN() function.

SELECT SIN(1.5707963267948966) AS Sin_Val;

Output :

Sin_Val
1

Example-3 : Sine of -90 degree i.e -1.5707963267948966 radian using SIN() function.

SELECT SIN(-1.5707963267948966) AS Sin_Val;

Output :

Sin_Val
-1

Example-4 : Sine value of a numeric column in a table. Table – Number

X
-1.22
-0.5
0
0.54
1.55
SELECT X, SIN(X) AS Sin_X  
FROM Number;

Output :

X Sin_X
-1.22 -0.9390993563190676
-0.5 -0.479425538604203
0 0
0.54 0.5141359916531132
1.55 0.999783764189357

2. COS() Function : COS() function in MySQL is used to return the cosine of any given number X, where X is given in radians. Syntax :

COS(X)

Parameter : Required. X : A number whose co-sine value we want to calculate. It is given in radian. Returns : It returns the cosine of given number x. Example-1 : Co-Sine of 0 using COS() function.

SELECT COS(0) AS  Cos_Val;

Output :

Cos_Val
1

Example-2 : Co-Sine of 90 degree i.e 1.5707963267948966 radian using COS() function.

SELECT COS(1.5707963267948966) AS  Cos_Val;

Output :

Cos_Val
0

Example-3 : Co-Sine value of a numeric column in a table. Table – Number

X
-1.22
-0.5
0
0.25
1.55
SELECT X, COS(X) AS Cos_X  
FROM Number;

Output :

X Cos_X
-1.22 0.34364574631604705
-0.5 0.8775825618903728
0 1
0.25 0.9689124217106447
1.55 0.020794827803092428

Both SIN() and COS() functions can be used in SQL queries to perform mathematical calculations involving trigonometric functions. Note that the input to these functions should be in radians, not degrees, so you may need to convert the input if you are working with degree-based angles.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads