Different ways to get ARC Tangent(ATAN, ATAN2) values of two variables 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(B, A) and ATAN2(B, A) is a mathematical function. It returns the arc tangent  of two variables .i.e A and B. It is the same as calculation B / A, except that the sign of both the argument determines the quadrant of the result.

It returns NULL, if input is passed as NULL.

It returns Warning, if any string argument is passed.


MySQL ATAN() and ATAN2() : Syntax

ATAN (B, A);
OR
ATAN2 (B, A);

MySQL ATAN() and ATAN2() : Parameter

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


MySQL ATAN() and ATAN2() : Output

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


MySQL ATAN() and ATAN2() Available from : MySQL 4.0


ATAN() and ATAN2() Example 1 : Very Basic example

Below is a very easy example. See the value when we pass the input as A as-4, B as 3. Both functions are returning the same value.

mysql> SELECT ATAN(-4,3);
+---------------------+
| ATAN(-4,3) |
+---------------------+
| -0.9272952180016122 |
+---------------------+
1 row in set (0.03 sec)

mysql> SELECT ATAN2(-4,3);
+---------------------+
| ATAN2(-4,3) |
+---------------------+
| -0.9272952180016122 |
+---------------------+
1 row in set (0.00 sec)

ATAN() and ATAN2() Example 2 :

Below are some more examples.

mysql> SELECT ATAN(PI(),-3);
+-------------------+
| ATAN(PI(),-3) |
+-------------------+
| 2.333143860959771 |
+-------------------+
1 row in set (0.04 sec)

mysql> SELECT ATAN(8,PI());
+--------------------+
| ATAN(8,PI()) |
+--------------------+
| 1.1965996462722117 |
+--------------------+
1 row in set (0.00 sec)

mysql> SELECT ATAN2(PI(),-3);
+-------------------+
| ATAN2(PI(),-3) |
+-------------------+
| 2.333143860959771 |
+-------------------+
1 row in set (0.03 sec)

mysql> SELECT ATAN2(8,PI());
+--------------------+
| ATAN2(8,PI()) |
+--------------------+
| 1.1965996462722117 |
+--------------------+
1 row in set (0.00 sec)

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

See the below example :

mysql> SELECT ATAN('test',-3);
+-------------------+
| ATAN('test',-3) |
+-------------------+
| 3.141592653589793 |
+-------------------+
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)

mysql> SELECT ATAN2(5,'test');
+--------------------+
| ATAN2(5,'test') |
+--------------------+
| 1.5707963267948966 |
+--------------------+
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() and ATAN2() Example 4 : NULL arguments

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

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

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

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

mysql> SELECT ATAN2(6,NULL);
+---------------+
| ATAN2(6,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(.2,.5);
+--------------------+
| ATAN(.2,.5) |
+--------------------+
| 0.3805063771123649 |
+--------------------+
1 row in set (0.03 sec)

With expression, it’s returning the same value as the above example.

mysql> SELECT ATAN(.1+.1,.2+.3);
+--------------------+
| ATAN(.1+.1,.2+.3) |
+--------------------+
| 0.3805063771123649 |
+--------------------+
1 row in set (0.03 sec)

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

mysql> SELECT ATAN2(9,5);
+--------------------+
| ATAN2(9,5) |
+--------------------+
| 1.0636978224025597 |
+--------------------+
1 row in set (0.00 sec)

With expression, it’s returning the same value as the above example.

mysql> SELECT ATAN2(2+7,1+4);
+--------------------+
| ATAN2(2+7,1+4) |
+--------------------+
| 1.0636978224025597 |
+--------------------+
1 row in set (0.00 sec)

You can see in the below screen that both inputs yield the same results.

mysql> SELECT (.2*2),(.5*2);
+--------+--------+
| (.2*2) | (.5*2) |
+--------+--------+
| 0.4 | 1.0 |
+--------+--------+
1 row in set (0.00 sec)

mysql> SELECT ATAN(.2*2,.5*2);
+--------------------+
| ATAN(.2*2,.5*2) |
+--------------------+
| 0.3805063771123649 |
+--------------------+
1 row in set (0.01 sec)

mysql> SELECT ATAN2(.2*2,.5*2);
+--------------------+
| ATAN2(.2*2,.5*2) |
+--------------------+
| 0.3805063771123649 |
+--------------------+
1 row in set (0.01 sec)

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


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

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.…

6 months ago