How TAN() Works in MariaDB

In MariaDB, TAN() is a built-in numeric function that returns the tangent of its argument.

Syntax

The syntax goes like this:

TAN(X)

Where X is the number for which to return the tangent.

Example

Here’s an example:

SELECT TAN(1.5672);

Result:

+-------------------+
| TAN(1.5672)       |
+-------------------+
| 278.0602948059405 |
+-------------------+

Here are some more examples:

SELECT 
    TAN(0),
    TAN(1),
    TAN(PI());

Result:

+--------+-------------------+-------------------------+
| TAN(0) | TAN(1)            | TAN(PI())               |
+--------+-------------------+-------------------------+
|      0 | 1.557407724654902 | -1.2246467991473532e-16 |
+--------+-------------------+-------------------------+

Negative Argument

Negative arguments are perfectly valid.

Example:

SELECT TAN(-2.17873);

Result:

+--------------------+
| TAN(-2.17873)      |
+--------------------+
| 1.4370963009569087 |
+--------------------+

Non-Numeric Argument

Here’s what happens when we provide a non-numeric argument:

SELECT TAN('Two');

Result:

+------------+
| TAN('Two') |
+------------+
|          0 |
+------------+
1 row in set, 1 warning (0.000 sec)

Let’s check the warning:

SHOW WARNINGS;

Result:

+---------+------+-----------------------------------------+
| Level   | Code | Message                                 |
+---------+------+-----------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'Two' |
+---------+------+-----------------------------------------+

Invalid Argument Count

Calling TAN() without an argument results in an error:

SELECT TAN();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'TAN'

And:

SELECT TAN(1, 2);

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'TAN'