How the ATAN() function works in Mariadb?
The ATAN()
function in MariaDB is used to calculate the arc tangent of a number.
The ATAN()
function in MariaDB is used to calculate the arc tangent of a number. The arc tangent is the inverse of the tangent function, which means it returns the angle in radians whose tangent is the specified number.
Syntax
The syntax for the MariaDB ATAN()
function is as follows:
ATAN(expression)
The expression
parameter is a numeric value, and the function returns the arc tangent of the expression as a value in radians.
Examples
Example 1: Basic Usage of ATAN()
This example demonstrates the basic usage of the ATAN()
function by calculating the arc tangent of 0.
SELECT ATAN(0);
+---------+
| ATAN(0) |
+---------+
| 0 |
+---------+
The output shows that the arc tangent of 0 is 0 radians.
Example 2: Arc Tangent of 1
This example calculates the arc tangent of 1, which should be π/4 radians or approximately 0.7854 radians.
SELECT ATAN(1);
+--------------------+
| ATAN(1) |
+--------------------+
| 0.7853981633974483 |
+--------------------+
The output confirms that the arc tangent of 1 is π/4 radians.
Example 3: Arc Tangent of -1
Here, we calculate the arc tangent of -1, which should be -π/4 radians or approximately -0.7854 radians.
SELECT ATAN(-1);
+---------------------+
| ATAN(-1) |
+---------------------+
| -0.7853981633974483 |
+---------------------+
The output shows that the arc tangent of -1 is -π/4 radians.
Example 4: Arc Tangent of a Large Number
In this example, we find the arc tangent of a large number.
SELECT ATAN(1000);
+--------------------+
| ATAN(1000) |
+--------------------+
| 1.5697963271282298 |
+--------------------+
The output indicates that the arc tangent of a large number approaches π/2 radians.
Example 5: Using ATAN()
with a Table
First, we create a table with sample data:
DROP TABLE IF EXISTS tangents;
CREATE TABLE tangents (tangent_value DOUBLE);
INSERT INTO tangents VALUES (0), (1), (-1), (1000), (-1000);
Now, we can calculate the arc tangent for each value in the table:
SELECT tangent_value, ATAN(tangent_value) AS arc_tangent FROM tangents;
+---------------+---------------------+
| tangent_value | arc_tangent |
+---------------+---------------------+
| 0 | 0 |
| 1 | 0.7853981633974483 |
| -1 | -0.7853981633974483 |
| 1000 | 1.5697963271282298 |
| -1000 | -1.5697963271282298 |
+---------------+---------------------+
The output displays the arc tangent for each tangent value in the table.
Related Functions
Below are a few functions related to the MariaDB ATAN()
function:
- MariaDB
TAN()
function is used to calculate the tangent of an angle specified in radians. - MariaDB
ATAN2()
function calculates the arc tangent of two variables ( y ) and ( x ), returning the angle in radians between the positive x-axis and the point ( (x, y) ).
Conclusion
The ATAN()
function in MariaDB is a mathematical function that provides the arc tangent of a given number, returning the result in radians. It is particularly useful in trigonometry and when dealing with angles in various mathematical computations within SQL queries. Understanding how to use this function and its related functions can be very beneficial for database developers and analysts working with geometric data or complex calculations.