COSD

Compute the cosine of an angle supplied in degrees, returning exact values at common angles.

Category: numericReturns: DOUBLEDialect: PostgreSql

Syntax

COSD(degrees)

Description

## Overview Returns the cosine of an angle expressed in degrees. COSD avoids the explicit RADIANS() conversion that COS requires and is implemented to return mathematically exact values at the angles where cosine takes a simple closed-form value (0, 90, 180, 270, and so on). This special-case handling is the main advantage over COS(RADIANS(x)), which returns a tiny floating-point residue at 90 degrees rather than exactly 0. For all other inputs, COSD is functionally identical to COS(RADIANS(x)): inputs are implicitly cast to DOUBLE, the mathematical cosine is evaluated, and the result is a DOUBLE in [-1, 1]. ## Behavior - Accepts any numeric type implicitly castable to DOUBLE. - Returns a DOUBLE in [-1, 1]. - Returns NULL if the argument is NULL. - Returns exact values at integer multiples of 90 degrees: COSD(0) = 1, COSD(90) = 0, COSD(180) = -1, COSD(270) = 0. - Preserves the even property: COSD(-x) = COSD(x). ## Numeric precision - For multiples of 90 degrees, COSD returns the mathematically exact value without floating-point residue. - For other angles, precision matches COS(RADIANS(x)) plus the rounding in RADIANS conversion (typically one ULP). - For very large degree magnitudes, argument reduction loses precision in the same way as COS. ## Compatibility - Matches the PostgreSQL COSD scalar function. - Complements COS (radian input) and COSD (degree input) in dialects that offer both.

Parameters

NameTypeDescription
degreesSpecifies the angle in degrees. Accepts any numeric type implicitly castable to DOUBLE. Negative and beyond-360 values are valid; the conversion is a pure cosine of the equivalent radian angle with special-case exact handling for multiples of 90 degrees.

Examples

-- Basic literal
SELECT COSD(0);  -- 1.0
-- Exact at 90 degrees
SELECT COSD(90);  -- 0.0
-- Common angle
SELECT COSD(60);  -- 0.5
-- Exact at 180 degrees
SELECT COSD(180);  -- -1.0
-- Negative angle
SELECT COSD(-90);  -- 0.0
-- NULL propagation
SELECT COSD(NULL);  -- NULL

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →