python math.ldexp()方法

ldexp()语法

math.ldexp(x, i, /)

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

    Return x * (2**i).
    
    This is essentially the inverse of frexp().

即,math.ldexp()接收两个参数x和i,返回x*(2**i),其本质上是math.frexp()的反函数。


参数

参数描述
xreal number,如int或float等类型
ireal number,如int或float等类型

返回值

Python float类型值。


math.ldexp()实例代码

>>> import math
>>> math.ldexp(3,2)
12.0
>>> math.ldexp(-5,2)
-20.0
>>> math.ldexp(0,0)
0.0
>>> math.ldexp('1','3') #参数must be 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.