小编lit*_*Yii的帖子

为什么 x*x 和 x**2 会返回不同的结果?

x = 1.5 * 10 ** 156
print(x * x)
print(x ** 2)
Run Code Online (Sandbox Code Playgroud)

x * x并且x ** 2在数学上是等价的。但当x较大时,前者可以返回 的结果inf,而后者会引发溢出错误。

x = 1.5 * 10 ** 156
print(x * x)
print(x ** 2)
Run Code Online (Sandbox Code Playgroud)

为什么会这样呢?

python floating-point

10
推荐指数
1
解决办法
197
查看次数

标签 统计

floating-point ×1

python ×1