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

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

6 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

6 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

6 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

6 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

6 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

7 months ago