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()的反函数。
参数 | 描述 |
---|---|
x | real number,如int或float等类型 |
i | real number,如int或float等类型 |
Python float类型值。
>>> 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-2023 笨鸟工具 x1y1z1.com All Rights Reserved.