1e400 == 10**400 是假吗?
在 Python 中,1e400
计算结果为 inf
,但 10**400
打印效果很好。理论上,1e(x) 应该是 10**x
,但是为什么以及何时会出现这种情况呢?
同样,1e5 == 10**5
计算结果为 True
,而 1e40 == 10**40
计算结果为 错误。然后,
int(1e22)
显示 1 和 22 个零,而 int(1e23)
显示 99999999999999991611392
。与此同时, 10**100000
仍然可以正常打印。 (虽然十到百万会冻结我的计算机,但它仍然没有给我一个溢出错误。)
这种不准确的背后是什么? 1e()
是否不如 10**()
?
In Python, 1e400
evaluates to inf
, but 10**400
prints out just fine. Theoretically, 1e(x) is supposed to be 10**x
, but why and when does this break down?
In a related vein, 1e5 == 10**5
evaluates to True
, while 1e40 == 10**40
evaluates to False
. Then while int(1e22)
shows a 1 with 22 zeros, int(1e23)
shows 99999999999999991611392
. Meanwhile, 10**100000
is still printing out just fine. (Although ten to the million is freezing up my computer, it still isn't giving me an overflow error.)
What's behind this inaccuracy? Is 1e()
inferior to 10**()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用不同的类型
Int 在 python 中可以变得任意大.. float ...没有那么多。
You are using different types
Int can get arbitrarily big in python .. float ... not so much.