log1p

log1p(x)

log1p(x, base)

Try it yourself:

See also:

log1p(): Accurate log(1 + x)

log1p() calculates log(1+x) with improved accuracy when x is close to zero. Directly adding a tiny x to 1 can lose significant digits in floating-point arithmetic, making log1p preferable in numerical and statistical formulas.

Domain and use

For real arithmetic, x must be greater than −1. log1p(0) is zero. It is useful for small percentage changes, probability formulas, and stable transformations. Its natural companion is expm1(), which accurately calculates exp(x)−1.

Use log() for ordinary values where the expression is not specifically 1+x. For very small inputs, retain full precision and avoid rounding until output with format().

All functions