# megengine.functional.log1p¶

log1p(x)[源代码]

Element-wise $$\log(1 + x)$$ function.

Calculates an approximation to $$\log(1 + x)$$:

$y_i = \log(1 + x_i)$

where log refers to the natural (base $$e$$) logarithm, for each element $$x_i$$ of the input tensor $$x$$.

This function has domain [-1, +infinity] and codomain [-infinity, +infinity].

x – input tensor. Should have a floating-point data type.

a tensor containing the evaluated result for each element in $$x$$. The returned tensor must have a floating-point data type determined by 类型提升规则.

This function is more accurate than $$\log(1+x)$$ for small values of input. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.

Special cases

For floating-point operands,

• If $$x_i$$ is NaN, the result is NaN.

• If $$x_i$$ is less than -1, the result is NaN.

• If $$x_i$$ is -1, the result is -infinity.

• If $$x_i$$ is -0, the result is -0.

• If $$x_i$$ is +0, the result is +0.

• If $$x_i$$ is +infinity, the result is +infinity.

>>> F.log(1e-10 + 1)
Tensor(0.0, device=xpux:0)
>>> F.log1p(1e-10)
Tensor(1e-10, device=xpux:0)