In PostgreSQL, atan()
is a mathematical function that returns the angle, in radians, whose tangent is a specified expression.
In trigonometry, this is known as the arctangent. The arctangent is the inverse of the tangent.
The arctangent is used when you know what the tangent of an angle is, but you want to know what the actual angle is.
Syntax
The syntax goes like this:
atan(x)
Where x
is a double precision value that represents the tangent of the angle you’re trying to determine.
Example
Here’s an example to demonstrate how it works.
SELECT atan(1);
Result:
0.7853981633974483
As mentioned, the argument represents the tangent, which itself can be returned with the tan()
function.
Therefore, we can do the following to verify this.
SELECT atan(tan(1));
Result:
1
Fractions
The argument can contain a fractional component.
SELECT atan(1.6197);
Result:
1.0176820992229842
Negative Argument
The argument can also be negative.
SELECT atan(-1.6197);
Result:
-1.0176820992229842
Expressions
The argument can include expressions.
SELECT atan(.5 * .45);
Result:
0.2213144423477913
Return the Angle in Degrees
As mentioned, atan()
returns its argument in radians. To get it in degrees, use the atand()
function.
The atand()
function works exactly the same as atan()
, except that its argument is returned in degrees instead of radians.