How to return COTANGENT COT() values in MySQL8?

With MySQL, we can do complex calculations very easily with the help of inbuilt mathematical functions. COT(number) helps in getting the cotangent value.

Now let’s start with it.


COT(X) is a mathematical function. It returns the cotangent of number X. Where X is the argument, whose value will be passed by the user.

It returns NULL, if X is passed as NULL.

It returns Error, if any String argument or Zero is passed.


MySQL COT() : Syntax

COT ( X );

MySQL COT() : Parameter

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


MySQL COT() : Output

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


MySQL COT()  Available from : MySQL 4.0


COT() Example 1 :

See the below example. See the output, when 12 is passed.

mysql> SELECT COT(12);
+---------------------+
| COT(12) |
+---------------------+
| -1.5726734063976893 |
+---------------------+
1 row in set (0.00 sec)

Now, Let’s change the input value to 56. See what it returns.

mysql> SELECT COT(56);
+---------------------+
| COT(56) |
+---------------------+
| -1.6359284217814665 |
+---------------------+
1 row in set (0.00 sec)

See the below value When 1 is passed as an input.

mysql> SELECT COT(1);
+--------------------+
| COT(1) |
+--------------------+
| 0.6420926159343306 |
+--------------------+
1 row in set (0.00 sec)

COT() Example 2 : Using it with PI()

We are using the PI() function to get the value of cotangent with it. I get the below value.

mysql> SELECT COT(PI());
+-----------------------+
| COT(PI()) |
+-----------------------+
| -8.165619676597685e15 |
+-----------------------+
1 row in set (0.00 sec)

COT() Example 3 : Some more examples

Below are some more examples.

mysql> SELECT COT(29.56);
+--------------------+
| COT(29.56) |
+--------------------+
| 0.2931169938865947 |
+--------------------+
1 row in set (0.00 sec)

mysql> SELECT COT(-29.56);
+---------------------+
| COT(-29.56) |
+---------------------+
| -0.2931169938865947 |
+---------------------+
1 row in set (0.01 sec)

mysql> SELECT COT(156.89);
+--------------------+
| COT(156.89) |
+--------------------+
| -5.209989733425108 |
+--------------------+
1 row in set (0.01 sec)

mysql> SELECT COT(-156.89);
+-------------------+
| COT(-156.89) |
+-------------------+
| 5.209989733425108 |
+-------------------+
1 row in set (0.00 sec)

COT() Example 3 : return ERROR if 0 is passed as an argument.

COT(0), when zero is passed as an input string it will show an error.

mysql> SELECT COT(0);
ERROR 1690 (22003): DOUBLE value is out of range in 'cot(0)'

COT() Example 4 : return error if any string argument is passed.

See the below example :

mysql> SELECT COT('test');
ERROR 1690 (22003): DOUBLE value is out of range in 'cot('test')'

mysql> SHOW ERRORS;
+-------+------+-----------------------------------------------+
| Level | Code | Message |
+-------+------+-----------------------------------------------+
| Error | 1690 | DOUBLE value is out of range in 'cot('test')' |
+-------+------+-----------------------------------------------+
1 row in set (0.00 sec)

You can see the ERROR message details with the help of the ‘SHOW ERRORS’ command. Please refer above code for the same.


COT() Example 5 : NULL arguments

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

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

Related articles : PI(), COS(), MySQL Maths.

You may also like...