In MariaDB, ATAN2()
is a built-in numeric function that returns the arctangent (inverse tangent) of its two arguments.
Syntax
The syntax goes like this:
ATAN2(Y,X)
The result is similar to calculating the arc tangent of Y / X
, except that the signs of both arguments are used to determine the quadrant of the result.
It can also be called without the 2
:
ATAN(Y,X)
Bear in mind that ATAN()
is considered a different function that normally accepts a single argument. However, it can be called with either one or two arguments. Calling it with two arguments returns the same as calling ATAN2()
with two arguments.
Example
Here’s an example to demonstrate this function:
SELECT ATAN2(2, 3);
Result:
+--------------------+ | ATAN2(2, 3) | +--------------------+ | 0.5880026035475675 | +--------------------+
Here are some more examples:
SELECT
ATAN2(-2, 3),
ATAN2(-1, 0),
ATAN2(2, -3);
Result:
+---------------------+---------------------+--------------------+ | ATAN2(-2, 3) | ATAN2(-1, 0) | ATAN2(2, -3) | +---------------------+---------------------+--------------------+ | -0.5880026035475675 | -1.5707963267948966 | 2.5535900500422257 | +---------------------+---------------------+--------------------+
The ATAN()
Function
As mentioned, calling ATAN()
with two arguments returns the same result as calling ATAN2()
with two arguments:
SELECT
ATAN(2, 3),
ATAN2(2, 3);
Result:
+--------------------+--------------------+ | ATAN(2, 3) | ATAN2(2, 3) | +--------------------+--------------------+ | 0.5880026035475675 | 0.5880026035475675 | +--------------------+--------------------+
Non-Numeric Arguments
Here’s what happens when we provide a non-numeric argument:
SELECT ATAN2('Ten', 'Four');
Result:
+----------------------+ | ATAN2('Ten', 'Four') | +----------------------+ | 0 | +----------------------+ 1 row in set, 2 warnings (0.000 sec)
Let’s check the warning:
SHOW WARNINGS;
Result:
+---------+------+------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'Ten' | | Warning | 1292 | Truncated incorrect DOUBLE value: 'Four' | +---------+------+------------------------------------------+
Missing Arguments
Calling ATAN2()
without an argument results in an error:
SELECT ATAN2();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'ATAN2'