How to get ARC Cosine(ACOS) value in MySQL8?

With MySQL, we can do complex calculations very easily with the help of inbuilt mathematical functions. ACOS(number) helps in getting the angle, in radians, whose sine is provided as input number. Now let’s start with these.


ACOS(number) is a mathematical function. It returns the arc cosine of number, that is, the value whose cosine is number. It returns NULL, if N is not in the range -1.00 to 1.00.

It returns Warning, if any string argument is passed.


MySQL ACOS() : Syntax

ACOS (number)

MySQL ACOS() : Parameter

Name, Required /Optional,Type, Description
number , Required, Double , It represents valid number between -1 and 1.


MySQL ACOS() : Output

Return, Description
NULL, if the argument is NULL.
Double, It returns arc cosine of number.


MySQL ACOS()  Available from : MySQL 4.0


ACOS() Example 1 :

See the below example. What it returns when 0 is passed.

mysql> select ACOS(0);
+--------------------+
| ACOS(0) |
+--------------------+
| 1.5707963267948966 |
+--------------------+
1 row in set (0.00 sec)

See the below value When -1 is passed as an input.

mysql> select ACOS(-1);
+-------------------+
| ACOS(-1) |
+-------------------+
| 3.141592653589793 |
+-------------------+
1 row in set (0.00 sec)

See the below value When 1 is passed as an input.

mysql> select ACOS(1);
+---------+
| ACOS(1) |
+---------+
| 0 |
+---------+
1 row in set (0.00 sec)

ACOS() Example 2 :

Below are some more examples.

mysql> SELECT ACOS(.13256);
+--------------------+
| ACOS(.13256) |
+--------------------+
| 1.4378449969525082 |
+--------------------+
1 row in set (0.00 sec)

mysql> SELECT ACOS(-.13256);
+-------------------+
| ACOS(-.13256) |
+-------------------+
| 1.703747656637285 |
+-------------------+
1 row in set (0.00 sec)

ACOS() Example 3 : return Warning if any string argument is passed.

See the below example :

mysql> SELECT ACOS('TEST123');
+--------------------+
| ACOS('TEST123') |
+--------------------+
| 1.5707963267948966 |
+--------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SHOW WARNINGS;
+---------+------+---------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'TEST123' |
+---------+------+---------------------------------------------+
1 row in set (0.00 sec)

You can see the warning message with the help of the ‘SHOW WARNINGS’ command. Please refer above code for the same.


ACOS() Example 4 : NULL arguments

If the argument is NULL, it will return NULL. See the below example :

mysql> select ACOS(NULL);
+------------+
| ACOS(NULL) |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)

It will return NULL if the values which are passed are out of range values.

mysql> SELECT ACOS(2.5698);
+--------------+
| ACOS(2.5698) |
+--------------+
| NULL |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT ACOS(-72.5698);
+----------------+
| ACOS(-72.5698) |
+----------------+
| NULL |
+----------------+
1 row in set (0.00 sec)

ACOS() Example 5 : Using expressions

Here are some more examples to use the expression with the ACOS() function :

mysql> SELECT ACOS(.5);
+--------------------+
| ACOS(.5) |
+--------------------+
| 1.0471975511965979 |
+--------------------+
1 row in set (0.00 sec)

We are using an expression in the below example for the above number as (.2+.3) becomes .5. So, We have got the same value.

mysql> SELECT ACOS(.2+.3);
+--------------------+
| ACOS(.2+.3) |
+--------------------+
| 1.0471975511965979 |
+--------------------+
1 row in set (0.00 sec)

You can see, We have got 0.06 in the below example.

mysql> SELECT (.2*.3);
+---------+
| (.2*.3) |
+---------+
| 0.06 |
+---------+
1 row in set (0.00 sec)

We are using an expression in the below example for the above number as (.2*.3) becomes 0.06. So, We have got the same value.

mysql> SELECT ACOS(.2*.3);
+--------------------+
| ACOS(.2*.3) |
+--------------------+
| 1.5107602683496182 |
+--------------------+
1 row in set (0.00 sec)

mysql> SELECT ACOS(0.06);
+--------------------+
| ACOS(0.06) |
+--------------------+
| 1.5107602683496182 |
+--------------------+
1 row in set (0.00 sec)

MySQL Related articles : LOCATE(), HEX(), CONCAT(), CONCAT_WS() , LOWER(), LTRIM(), INSTR(), POSITION(), MySQL STRING FUNCTIONS.


PHP Related articles : SUBSTR_COMPARE(), STRNCMP(), STRNCASECMP(), STRNATCASECMP(), PHP STRING FUNCTIONS().

jyoti rani

Recent Posts

Exploring the Best Toy Store in Noida: A Paradise for Kids and Collectors

Toys have always played a crucial role in childhood, fueling imagination, creativity, and learning. Whether you're looking for educational playsets,…

2 days ago

A Unique Toy Shopping Experience: The Best Toy Store in Delhi and Across India

Toys are an essential part of childhood, shaping creativity, learning, and fun-filled memories. Whether it’s the soft embrace of plush…

3 days ago

A World of Play: The Best Toy Shopping Experience in Noida

Toys are a gateway to imagination, creativity, and learning. Whether it’s a child’s first plush toy, a set of engaging…

4 days ago

The Ultimate Guide to Finding the Best Toy Shops in Gurgaon

Toys are more than just playthings; they help children explore, learn, and develop essential life skills. From interactive sensory toys…

5 days ago

The Ultimate Toy Shopping Guide: Finding the Best Toy Store in Noida

Toys are more than just playthings; they are tools that foster creativity, motor skills, and cognitive development in children. From…

6 days ago

Exploring the Best Toy Shop in Delhi: A Blend of Fun, Learning, and Creativity

Toys play an integral role in a child’s growth and development. They spark creativity, encourage learning, and provide endless hours…

1 week ago