How Acosd() Works in PostgreSQL

In PostgreSQL, acosd() is a mathematical function that returns the inverse cosine of the specified expression, measured in degrees.

The inverse cosine is also known as the arccosine.

Syntax

The syntax goes like this:

acosd(x)

Where x is a double precision value.

Example

Here’s an example to demonstrate how it works.

SELECT acosd(0.5);

Result:

60

Out of Range Error?

The argument must range from -1.00 to 1.00. Any values outside this range will result in an error.

SELECT acosd(1.01);

Result:

ERROR: input is out of range

And here it is with a negative expression.

SELECT acosd(-1.01);

Result:

ERROR: input is out of range

Argument of Zero

An argument of zero returns 90 degrees, which is the equivalent of π/2.

SELECT acosd(0);

Result:

90

Cosine of Arccosine

Since arccosine is the inverse function of cosine, the cosine of arccosine of x is equal to x.

We can pass acosd() to the cosd() function as an argument in order to demonstrate this.

SELECT cosd(acosd(0.90));

Result:

0.9

Return the Arccosine in Radians

As mentioned, acosd() returns the arccosine in degrees. To return the arccosine in radians, use the acos() function.

The acos() function works exactly the same as acosd(), except that it returns its result in radians instead of degrees.