python math.ldexp() 方法
python math.ldexp(x, i) 方法返回 x * (2**i),math.frexp() 的反函数。
python 版本:2.6
语法math.ldexp() 方法语法如下:
math.ldexp(x, i)
参数说明:
- x -- 必需,一个正数或负数。如果值不是数字,则返回 typeerror。
- i -- 必需,一个正数或负数。如果值不是数字,则返回 typeerror。
一个浮点值,返回 x * (2**i)
实例以下实例计算 x * (2**i):
实例
# 导入 math 包
import math
# 返回 x * (2**i)
print(math.ldexp(9, 3))
print(math.ldexp(-5, 2))
print(math.ldexp(15, 2))
import math
# 返回 x * (2**i)
print(math.ldexp(9, 3))
print(math.ldexp(-5, 2))
print(math.ldexp(15, 2))
输出结果:
72.0 -20.0 60.0
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!