How the ASIN() function works in Mariadb?

The ASIN() function in MariaDB is used to calculate the arc sine of a given number.

Posted on

The ASIN() function in MariaDB is used to calculate the arc sine of a given number. The arc sine is the inverse of the sine function, which means that it returns the angle whose sine is the specified number.

Syntax

The syntax for the MariaDB ASIN() function is as follows:

ASIN(expression)

The expression parameter is a numeric value between -1 and 1, representing the sine of the angle you wish to calculate. The function returns the angle in radians.

Examples

Example 1: Basic Usage of ASIN()

This example demonstrates the basic usage of the ASIN() function by calculating the arc sine of 0.

SELECT ASIN(0);
+---------+
| ASIN(0) |
+---------+
|       0 |
+---------+

The output shows that the arc sine of 0 is 0 radians.

Example 2: Arc Sine of 1

This example calculates the arc sine of 1, which should be π/2 radians or approximately 1.5708 radians.

SELECT ASIN(1);
+--------------------+
| ASIN(1)            |
+--------------------+
| 1.5707963267948966 |
+--------------------+

The output confirms that the arc sine of 1 is π/2 radians.

Example 3: Arc Sine of -1

Here, we calculate the arc sine of -1, which should be -π/2 radians or approximately -1.5708 radians.

SELECT ASIN(-1);
+---------------------+
| ASIN(-1)            |
+---------------------+
| -1.5707963267948966 |
+---------------------+

The output shows that the arc sine of -1 is -π/2 radians.

Example 4: Arc Sine of 0.5

In this example, we find the arc sine of 0.5.

SELECT ASIN(0.5);
+--------------------+
| ASIN(0.5)          |
+--------------------+
| 0.5235987755982989 |
+--------------------+

The output indicates that the arc sine of 0.5 is approximately 0.5236 radians.

Example 5: Using ASIN() with a Table

First, we create a table with sample data:

DROP TABLE IF EXISTS angles;
CREATE TABLE angles (sine_value DOUBLE);
INSERT INTO angles VALUES (0), (0.5), (1), (-1), (-0.5);

Now, we can calculate the arc sine for each value in the table:

SELECT sine_value, ASIN(sine_value) AS arc_sine FROM angles;
+------------+---------------------+
| sine_value | arc_sine            |
+------------+---------------------+
|          0 |                   0 |
|        0.5 |  0.5235987755982989 |
|          1 |  1.5707963267948966 |
|         -1 | -1.5707963267948966 |
|       -0.5 | -0.5235987755982989 |
+------------+---------------------+

The output displays the arc sine for each sine value in the table.

Below are a few functions related to the MariaDB ASIN() function:

  • MariaDB SIN() function is used to calculate the sine of an angle specified in radians.
  • MariaDB ACOS() function calculates the arc cosine of a number, which is the inverse of the cosine function.
  • MariaDB ATAN() function computes the arc tangent of a number, returning the angle whose tangent is the specified number.

Conclusion

The ASIN() function in MariaDB is a straightforward yet powerful mathematical function that allows users to calculate the arc sine of a number, providing the angle in radians. Understanding how to use this function, along with its related functions, can be very useful in various mathematical and trigonometric calculations within SQL queries.