MySQL ASIN() – Find the arcsine of a number in MySQL

ASIN Function

In this tutorial, we will study the MySQL ASIN() function. In maths, you must have come across the function – asin. The arcsine of a number x is the inverse sine function of x where x is a number between -1 and 1. Like all other trigonometric operations, asin is widely used and that’s why MySQL provides us with the ASIN() function. ASIN() returns the arcsine of a number. As evident, it is the inverse of the SIN() function. ASIN() returns the angle whose sine value is passed a parameter to it. Let us dive into the syntax and examples of ASIN() now.


Syntax of MySQL ASIN()

ASIN(number);Code language: SQL (Structured Query Language) (sql)

Where ‘number’ is a number whose arcsine is to be found. Note that, ‘number’ should have a value between -1 and 1.


Examples of MySQL ASIN()

Let us start with some basic examples now. We have the following three expressions – asin 0.2, asin 1 and asin -1. We will find their values in MySQL using the ASIN() function with the SELECT statement.

SELECT ASIN(0.2); 
SELECT ASIN(1); 
SELECT ASIN(-1);Code language: SQL (Structured Query Language) (sql)

And we get the output as,

MySQL ASIN Basic Examples

MySQL ASIN() With Numbers Out Of Range

Now earlier I mentioned a couple of times that the ‘number’ parameter should be a value between -1 (inclusive) and 1 (inclusive). But, what if you pass a value that is not in this range? Let us see that using the below example.

SELECT ASIN(5); 
SELECT ASIN(-15);Code language: SQL (Structured Query Language) (sql)

And the output is,

MySQL ASIN Out Of Range

When we pass numbers not in the range -1 and 1 to ASIN(), it returns NULL.

MySQL ASIN() With Expressions

We can also pass mathematical expressions as parameters inside the ASIN() function. Suppose you have the following two expressions – asin (0.5+0.2) and asin (0.5*0.3). We can do this in MySQL using the ASIN() using the below queries.

SELECT ASIN(0.5+0.2); 
SELECT ASIN(0.5*0.3);Code language: SQL (Structured Query Language) (sql)

And the output is,

MySQL ASIN Expressions

MySQL ASIN() With Zero and NULL

The arcsine of zero is zero. We can demonstrate this in MySQL using the below example.

SELECT ASIN(0);Code language: SQL (Structured Query Language) (sql)

And the output is,

Asin Zero

ASIN() returns NULL if the number passed to it is NULL. We can demonstrate this using the below example.

SELECT ASIN(NULL);Code language: SQL (Structured Query Language) (sql)

And we get the output as follows –

MySQL ASIN Null

ASIN() Is The Inverse Of SIN()

As mentioned earlier in the introduction, ASIN() is the inverse of SIN(). Suppose the sine of y is equal to x. That is,

sin y = x

Then the arcsine of x is equal to the inverse sine function of x, which is therefore, equal to y:

arcsin x = sin-1 x = y

Let us demonstrate this using the below example.

SELECT ASIN(SIN(0.5));Code language: SQL (Structured Query Language) (sql)

First, we get the value of SIN(0.5) which is roughly 0.479. Now the result of the SIN() function is passed into the ASIN() function. Since ASIN() is the inverse of SIN(), it will return the numerical value that was passed to the SIN() function (0.5 in this example) as the result. Therefore, we get the output as follows –

Asin Sin

Using ASIN() With Tables

Consider the below ‘Angles’ table.

Asin Angles Table
Angles Table

Building on the previous example about how ASIN() is the inverse of SIN(), let us write a query that displays the Angle column and the arcsine of the values in the SineOfAngle column. We use aliases to make our output readable. The query is –

SELECT Angle, ASIN(SineOfAngle) AS Arcsine FROM Angles;Code language: SQL (Structured Query Language) (sql)

And the output is,

Asin Table Example 1

As you can see, the values in both columns are equal to each other.


Conclusion

Finding the arcsine of an angle is an important trigonometric operation. You will find yourself using the ASIN() function every time you deal with data with trigonometric operations.


References