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.

jyoti rani

Recent Posts

What Is a Progressive Web App? Why Would You Need One?

App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…

1 year ago

7 Most Popular Paid Online Advertising Strategy

As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…

1 year ago

The Importance of User-Centered Design in Mobile App Development

Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…

1 year ago

Healthcare Mobile App Development: A Complete Guide for Founders

COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…

1 year ago

Exploring Diverse WordPress Theme Niches: A Comprehensive Guide

Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…

1 year ago

8 Awesome Blog Content Ideas for Movers to Skyrocket the SEO

For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…

1 year ago