Skip to content

Compute the natural logarithm plus one

Description

This computes log(1 + x) but is more numerically stable for x close to zero.

Usage

<Expr>$log1p()

Value

A polars expression

Examples

library("polars")

pl$DataFrame(a = c(1, 2, 4))$
  with_columns(log1p = pl$col("a")$log1p())
#> shape: (3, 2)
#> ┌─────┬──────────┐
#> │ a   ┆ log1p    │
#> │ --- ┆ ---      │
#> │ f64 ┆ f64      │
#> ╞═════╪══════════╡
#> │ 1.0 ┆ 0.693147 │
#> │ 2.0 ┆ 1.098612 │
#> │ 4.0 ┆ 1.609438 │
#> └─────┴──────────┘