MySQL - ACOS() Function



ACOS() function of MySQL is used to calculate the arc cosine value of numerical data in the database tables.

Arc cosine function is a part of trigonometry and is defined as the inverse of the cosine function. In simple words, in a right-angled triangle, cosine function is defined as the ratio of an adjacent side of a non-right angle to the hypotenuse; but the arc cosine function is defined as its inverse, where the domain of cosine function becomes the range of arc cosine function and vice-versa.

This function accepts an integer number as an argument and returns the arc cosine value for the given integer.

Syntax

Following is the syntax of MySQL ACOS() function −

ACOS(x)

Parameters

This function takes an integer value between 1 and -1 representing a cosine as a parameter.

Return Value

This function returns the angle in radians of the given cosine value.

Example

The query calculates the arccosine of 0.8 (cosine inverse of 0.8) −

SELECT ACOS(0.8) As Result;

Output

This will produce the following result −

Result
0.6435011087932843

Example

You can also pass negative value to this function as shown below −

SELECT ACOS(-0.5) As Result;

Output

This will produce the following result −

Result
2.0943951023931957

Example

If the value passed is to this function is not in the range of -1 to 1 this function returns a NULL value −

SELECT ACOS(6) As Result;

Output

This will produce the following result −

Result
NULL

Example

This query calculates the arccosine (inverse cosine) of the value 1 and returns the result. In this case, it will return the value 0, which is the arccosine of 1.

SELECT ACOS(1) As Result;

Output

This will produce the following result −

Result
0
Advertisements