IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

log1p

def log1p[dtype: DType, width: SIMDLength, //](x: SIMD[dtype, width]) -> SIMD[dtype, width] where dtype.is_floating_point()

Computes the log1p of the inputs.

The log1p(x) is equivalent to log(1+x), but stays accurate when x is close to zero, where 1 + x would round away the low bits of x.

The result is accurate to within 1 ulp for float32 and float64. float16 and bfloat16 inputs are computed in float32 and rounded once to the narrow type. Special values: log1p(±0) is ±0, log1p(-1) is -inf, log1p(+inf) is +inf, and NaN is returned for NaN and for x < -1.

Constraints:

The input must be a floating-point type.

Parameters:

  • ​dtype (DType): The dtype of the input and output SIMD vector.
  • ​width (SIMDLength): The width of the input and output SIMD vector.

Args:

Returns:

SIMD[dtype, width]: The log1p of the input.