python math.expm1()方法

math.expm1()语法

expm1(x, /)

python源码中对expm1()方法的介绍:

    Return exp(x)-1.
    
    This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.

python math模块中的expm1()方法,可以返回e自然常数的x次方-1的值,该方法可以避免一些精度上的损失。

提示:expm1()方法中的“1”为数字1。


参数

参数描述
xreal number,比如float、int类型的值

返回值

python float类型值


math.expm1()实例代码

>>> import math
>>> math.expm1(0)
0.0
>>> math.expm1(1) #自然常数e的值为2.718281828459045,即下方的math.e
1.7182818284590453
>>> math.e
2.718281828459045
>>> math.expm1('1') #传入的参数必须是real number
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be real number, not str

全栈后端 / Python库 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.