How Cotd() Works in PostgreSQL

In PostgreSQL, cotd() is a trigonometric function that returns the cotangent of the specified angle.

The angle is provided as an argument, specified in degrees.

In trigonometry, in a right triangle, the cotangent of an angle is the length of the adjacent side divided by the length of the opposite side.

Syntax

The syntax goes like this:

cotd(x)

Where x is a double precision value that is interpreted as number of radians.

Example

Here’s an example to demonstrate how it works.

SELECT cotd(45);

Result:

1

Fractions

The argument can contain a fractional component.

SELECT cotd(45.2490);

Result:

0.9913458158004194

Negative Argument

The argument can also be negative.

SELECT cotd(-23.56);

Result:

-2.2932722545025657

Expressions

The argument can include expressions.

SELECT cotd(2 * 14);

Result:

1.8807264653463318

Zero Argument

The argument provided to cotd() must be non-zero, as the cotangent of zero doesn’t exist.

Here’s the result I get when I pass zero as an argument.

SELECT cotd(0);

Result:

Infinity

Specify the Angle in Radians

As mentioned, cotd() accepts its argument in degrees. To provide it in radians, use the cot() function.

The cot() function works exactly the same as cotd(), except that its argument is specified in radians instead of degrees.