MySQL ATAN() Function – Return the Arc Tangent of a Value (or Values)

In MySQL, the ATAN() function returns the arc tangent of a value. It can also be used to return the arc tangent of two values.

You provide the value/s as an argument when calling the function.

Syntax

This function can be used in either of the following two ways:

ATAN(X)

Where X is the value for which you’d like the arc tangent returned.

It can also be used like this:

ATAN(Y,X)

In this case, it’s 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.

Example 1 – Basic Usage

Here’s a basic example that returns the arc tangent of a single value.

SELECT ATAN(1);

Result:

+--------------------+
| ATAN(1)            |
+--------------------+
| 0.7853981633974483 |
+--------------------+

And with another value.

SELECT ATAN(2.7);

Result:

+--------------------+
| ATAN(2.7)          |
+--------------------+
| 1.2160906747839564 |
+--------------------+

And with a negative value.

SELECT ATAN(-2.7);

Result:

+---------------------+
| ATAN(-2.7)          |
+---------------------+
| -1.2160906747839564 |
+---------------------+

Example 3 – Expressions

You can also pass in expressions like this:

SELECT ATAN(2.1 + 0.3);

Result:

+-------------------+
| ATAN(2.1 + 0.3)   |
+-------------------+
| 1.176005207095135 |
+-------------------+

Example 4 – With 2 Arguments

Here’s an example using two arguments.

SELECT ATAN(2, 1);

Result:

+--------------------+
| ATAN(2, 1)         |
+--------------------+
| 1.1071487177940904 |
+--------------------+

Example 5 – Passing in a Function

In this example I pass in the MySQL PI() function as one of the arguments.

SELECT ATAN(PI(), 1);

Result:

+--------------------+
| ATAN(PI(), 1)      |
+--------------------+
| 1.2626272556789118 |
+--------------------+