Compute the cotangent of an angle expressed in radians.
COT(expr)
## Overview Returns the cotangent of an angle supplied in radians. Cotangent is the reciprocal of tangent: COT(x) = COS(x) / SIN(x) = 1 / TAN(x). It appears in fluid dynamics, structural engineering, and any context where the inverse of a slope is more natural than the slope itself. Because cotangent is defined only where the sine is non-zero, its behavior near multiples of pi mirrors the singularities of tangent near odd multiples of pi/2: small input changes near the asymptote produce large output swings, and a floating-point evaluation at the exact multiple of pi returns a very large finite value rather than infinity. ## Behavior - Accepts any finite DOUBLE value. Mathematically undefined at integer multiples of pi. - Returns a DOUBLE value that is unbounded in magnitude. - Returns NULL if the argument is NULL. - Matches 1.0 / TAN(x) to within one ULP in the stable range. - Deterministic within a session. ## Numeric precision - Computed from COS(x) and SIN(x) using IEEE 754 double-precision intrinsics. - Near multiples of pi, sine approaches zero and the ratio becomes numerically unstable. - Argument magnitudes above roughly 1e15 lose meaningful precision because of range-reduction error in sine and cosine. ## Compatibility - Conforms to the SQL standard definition of COT as a scalar DOUBLE function. - Behaves consistently with typical mathematical library cotangent routines.
| Name | Type | Description |
|---|---|---|
expr | Specifies the angle in radians whose cotangent is returned. Accepts any finite DOUBLE value except integer multiples of pi (where the sine is zero and the cotangent is undefined). |
-- Basic literal: COT of pi/4 evaluates to 1
SELECT COT(PI() / 4);
-- Result: 1.0000000000000002
-- Reciprocal identity
SELECT COT(0.5), 1.0 / TAN(0.5);
-- Result: 1.8304877217124519, 1.8304877217124519
-- Small angle: cotangent grows large as the angle approaches 0
SELECT COT(0.001);
-- Result: 999.9996666666867
-- Near pi/2 cotangent approaches 0
SELECT COT(PI() / 2);
-- Result: 6.123233995736766E-17
-- NULL propagation
SELECT COT(NULL);
-- Result: NULL
-- Column use: convert slope angle into horizontal run per unit rise
SELECT beam_id, COT(RADIANS(angle_deg)) AS run_per_rise
FROM engineering.design.beams;