Compute the inverse cosine (arccosine) of a value, returning an angle in radians.
ACOS(expr)
## Overview Returns the inverse cosine of the input, producing an angle in radians whose cosine equals the input. The result lies in the closed interval [0, pi]. ACOS is the algebraic inverse of COS on its principal branch and is the primary ingredient in the spherical law of cosines and in cosine-similarity conversions to angular distance. Because the input must be a valid cosine value, ACOS is domain-restricted. Values slightly outside [-1, 1] caused by floating-point rounding (common when summing dot-product components of unit vectors) silently produce NULL, so defensive clamping is often necessary before the call. ## Behavior - Domain: [-1, 1]. Values strictly outside this range return NULL. - Range: [0, pi] radians. - Returns NULL if the argument is NULL. - Is strictly decreasing on its domain. - ACOS(COS(x)) equals x only for x in [0, pi]; for other x it returns the principal-value reflection. ## Numeric precision - Computed using the IEEE 754 double-precision acos routine. - Near x = +/-1 the derivative is unbounded, so tiny input noise produces large output swings. In practice this manifests as distance underestimation when two points are extremely close on the sphere. - For points within a few meters on a sphere, prefer the haversine formulation which uses ASIN instead of ACOS to avoid the near-1 cancellation. ## Compatibility - Conforms to the SQL standard definition of ACOS as a scalar DOUBLE function with domain [-1, 1]. - Matches typical mathematical library implementations.
| Name | Type | Description |
|---|---|---|
expr | Specifies the cosine value whose angle is returned. Must lie in the closed interval [-1, 1]. Values outside this range yield NULL. |
-- Basic literal: arccosine of 1 is 0
SELECT ACOS(1);
-- Result: 0.0
-- Arccosine of 0 is pi/2
SELECT ACOS(0);
-- Result: 1.5707963267948966
-- Arccosine of -1 is pi
SELECT ACOS(-1);
-- Result: 3.141592653589793
-- Convert to degrees
SELECT DEGREES(ACOS(0.5));
-- Result: 60.0
-- Out-of-domain input returns NULL
SELECT ACOS(2);
-- Result: NULL
-- Column use: angle between two unit vectors from their dot product
SELECT pair_id, ACOS(dot_product) AS angle_rad
FROM analytics.features.vector_pairs;