python math.log1p()方法
math.log1p()()方法
math模块的log1p()方法,接收一个参数x,可用于计算以自然常数e为底的1+x的对数。在x趋近于零时,该计算方式也是精确的。
log1p()语法
log1p(x)
python源码对log1p()方法的介绍:
Return the natural logarithm of 1+x (base e).
The result is computed in a way which is accurate for x near zero.
参数
参数 | 描述 |
---|---|
x | 必须参数,real number,如int或float等类型 |
返回值
float类型值。
math.log1p()方法实例代码
>>> import math
>>> math.log1p(1)
0.6931471805599453
>>> math.log1p(0)
0.0