Compute e^x - 1 with high precision for small x.
EXPM1(expr)
## Overview Returns e^x - 1. EXPM1 exists to preserve precision when x is small. The naive expression EXP(x) - 1 produces EXP(x) very close to 1, and the subtraction 1 - 1 cancels most significant digits. EXPM1 avoids this cancellation by computing the expansion directly. EXPM1 is paired with LOG1P for numerically stable round trips near zero and is the recommended primitive for short-duration interest accrual, small probability corrections in maximum-likelihood fits, and anywhere the quantity e^x - 1 arises naturally. ## Behavior - Domain: all finite DOUBLE values. - Range: (-1, infinity). - Returns NULL if the argument is NULL. - Returns exactly 0 for input 0. - Approaches -1 for very large negative x and overflows to infinity for very large positive x. - EXPM1(LOG1P(x)) equals x to within one ULP for all valid x. ## Numeric precision - Uses the IEEE 754 double-precision expm1 routine, accurate to within one ULP. - Near zero, preserves the leading-order behavior EXPM1(x) approximately equals x that would otherwise be lost to cancellation. - For |x| larger than roughly 0.5, the precision benefit is negligible; EXP(x) - 1 and EXPM1(x) agree to within one ULP. ## Compatibility - Conforms to the C99 and IEEE 754 expm1 conventions. - Matches typical mathematical library implementations.
| Name | Type | Description |
|---|---|---|
expr | Specifies the exponent. Accepts any finite DOUBLE value. For inputs above approximately 709 the result overflows to infinity. |
-- Basic literal
SELECT EXPM1(0);
-- Result: 0.0
-- EXPM1 of 1 is e - 1
SELECT EXPM1(1);
-- Result: 1.718281828459045
-- Precision advantage for small values
SELECT EXPM1(1E-10);
-- Result: 1.00000000005E-10
-- Compare with naive EXP(x) - 1
SELECT EXPM1(1E-15), EXP(1E-15) - 1;
-- Result: 1.0E-15, 1.1102230246251565E-15
-- Round-trip identity with LOG1P
SELECT EXPM1(LOG1P(2.5));
-- Result: 2.5
-- Column use: accurate small-interest compounding
SELECT loan_id, principal * EXPM1(rate * days / 365.0) AS accrued_interest
FROM finance.ledger.loans;