TAN

Compute the tangent of an angle expressed in radians.

Category: mathReturns: DOUBLEDialect: Standard

Syntax

TAN(expr)

Description

## Overview Returns the tangent of an angle supplied in radians. Tangent appears in slope calculations, projective geometry, field-of-view formulas, and in any trigonometric identity where sin/cos must be combined into a single ratio. Unlike SIN and COS, the tangent function is unbounded. It grows toward positive infinity as the angle approaches pi/2 from below, and toward negative infinity from above. Because the argument reduction is never exact, TAN at the theoretical singularity returns a very large finite number rather than producing an error. ## Behavior - Accepts any finite DOUBLE value. - Returns a DOUBLE that is unbounded. The output domain is the full real line. - Returns NULL if the argument is NULL. - Returns NaN for NaN input. Returns a very large magnitude near odd multiples of pi/2 rather than infinity. - Is deterministic and matches SIN(x) / COS(x) to within one ULP for normal inputs. ## Numeric precision - Evaluated using IEEE 754 double-precision tan. Accurate to within one ULP in the stable range. - Near odd multiples of pi/2, small input changes cause large output swings. Use TAN cautiously as a predicate on continuous data. - As with SIN and COS, argument magnitudes above 1e15 lose meaningful trigonometric precision. ## Compatibility - Conforms to the SQL standard. - Matches the behavior of IEEE 754 tan in typical mathematical libraries.

Parameters

NameTypeDescription
exprSpecifies the angle in radians whose tangent is returned. Accepts any finite DOUBLE value except odd multiples of pi/2 (where the tangent is undefined).

Examples

-- Basic literal
SELECT TAN(0);
-- Result: 0.0
-- Tangent of pi/4 evaluates to 1
SELECT TAN(PI() / 4);
-- Result: 0.9999999999999999
-- Convert degrees to radians first
SELECT TAN(RADIANS(45));
-- Result: 0.9999999999999999
-- Identity: TAN(x) = SIN(x) / COS(x)
SELECT TAN(0.5), SIN(0.5) / COS(0.5);
-- Result: 0.5463024898437905, 0.5463024898437905
-- Near-singularity: TAN(PI()/2) returns a very large (not infinite) value
SELECT TAN(PI() / 2);
-- Result: 1.633123935319537E16
-- Column use: slope of a line from angle
SELECT segment_id, TAN(RADIANS(incline_deg)) AS slope
FROM roads.catalog.segments;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →