Compute the natural logarithm (base e) of a positive number.
LN(expr)
## Overview Returns the natural logarithm (base e) of the input. LN is the algebraic inverse of EXP and is the canonical logarithm for calculus, continuous compounding, entropy calculations, and maximum-likelihood estimation. Every engine that exposes LOG without a base defaults to the natural logarithm. Because log is undefined for non-positive arguments, LN has a strict domain: x must be greater than zero. A zero or negative input produces NULL rather than raising an error, so you should always validate inputs explicitly when correctness depends on catching invalid data upstream. ## Behavior - Domain: (0, infinity). Zero and negative values return NULL. - Range: all real numbers. - Returns NULL if the argument is NULL. - Is strictly increasing: LN preserves order on its domain. - LN(1) is exactly 0. LN(EXP(1)) is exactly 1. - Integer inputs are implicitly cast to DOUBLE before evaluation. ## Numeric precision - Uses the IEEE 754 double-precision log routine, accurate to within one ULP. - For inputs very close to 1, LN(x) is numerically small and loses precision. Use LOG1P(x - 1) in that regime for maximum stability. - For very large inputs, LN grows slowly (LN(10^18) is about 41) and remains well within DOUBLE range. ## Compatibility - Conforms to the SQL standard definition of LN as a scalar DOUBLE function with domain x > 0. - Matches typical mathematical library implementations.
| Name | Type | Description |
|---|---|---|
expr | Specifies the positive input. Must be strictly greater than 0. Zero and negative values yield NULL. |
-- Basic literal: natural log of 1 is 0
SELECT LN(1);
-- Result: 0.0
-- LN of Euler's number is 1
SELECT LN(E());
-- Result: 1.0
-- LN of 10
SELECT LN(10);
-- Result: 2.302585092994046
-- Inverse relationship: LN(EXP(x)) = x
SELECT LN(EXP(5));
-- Result: 5.0
-- Domain violation: LN(0) and LN(-1) return NULL
SELECT LN(0) AS zero_input, LN(-1) AS negative_input;
-- Result: NULL, NULL
-- Column use: log-price for continuous returns
SELECT symbol, LN(close_price) - LN(LAG(close_price) OVER (PARTITION BY symbol ORDER BY trade_date)) AS log_return
FROM finance.markets.daily_prices;