How to get ARC Tangent(ATAN) value in MySQL8?

With MySQL, we can do complex calculations very easily with the help of inbuilt mathematical functions. ATAN() helps in getting the arc tangent of the input number. Now let’s start with these.


ATAN(number) is a mathematical function. It returns the arc tangent  of a number.

It returns NULL, if input is passed as NULL.

It returns Warning, if any string argument is passed.


MySQL ATAN() : Syntax

ATAN (number)

MySQL ATAN() : Parameter

Name, Required /Optional, Type, Description
number, Required, Double, It represents a valid number.


MySQL ATAN() : Output

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


MySQL ATAN()  Available from : MySQL 4.0


ATAN() Example 1 : Very Basic example

Below is a very easy example. See the value when we pass the input as 0.

mysql> SELECT ATAN(0);
+---------+
| ATAN(0) |
+---------+
| 0 |
+---------+
1 row in set (0.00 sec)

See the value when we pass the input as 1.

mysql> SELECT ATAN(1);
+--------------------+
| ATAN(1) |
+--------------------+
| 0.7853981633974483 |
+--------------------+
1 row in set (0.00 sec)

See the value when we pass the input as -1.

mysql> SELECT ATAN(-1);
+---------------------+
| ATAN(-1) |
+---------------------+
| -0.7853981633974483 |
+---------------------+
1 row in set (0.00 sec)

ATAN() Example 2 :

Below are some more examples.

mysql> SELECT ATAN(2.5);
+--------------------+
| ATAN(2.5) |
+--------------------+
| 1.1902899496825317 |
+--------------------+
1 row in set (0.00 sec)

mysql> SELECT ATAN(-2.5);
+---------------------+
| ATAN(-2.5) |
+---------------------+
| -1.1902899496825317 |
+---------------------+
1 row in set (0.00 sec)

ATAN() Example 3 : It will return Warning if any string argument is passed.

See the below example :

mysql> SELECT ATAN('test');
+--------------+
| ATAN('test') |
+--------------+
| 0 |
+--------------+
1 row in set, 1 warning (0.00 sec)

mysql> SHOW WARNINGS;
+---------+------+------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'test' |
+---------+------+------------------------------------------+
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.


ATAN() Example 4 : NULL arguments

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

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

ATAN() Example 5 : Using expressions

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

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

Now, we will get the same value if we pass the .5 as (.2+.3). See the below screen

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

Similarly for expression (-.2+.3) = .1. You can see in the below screen that both inputs yield the same results.

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

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

mysql> SELECT ATAN(.06);
+---------------------+
| ATAN(.06) |
+---------------------+
| 0.05992815512120788 |
+---------------------+
1 row in set (0.00 sec)

We are getting the same values when we are using expressions, rather than using the number directly.


Related articles : ABS(), ATAN2(), MySQL Maths.

You may also like...