1e400 == 10**400 是假吗?

发布于 2025-01-10 08:39:15 字数 494 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不放开 2025-01-17 08:39:15

您正在使用不同的类型

print (type(1e5))    # float
print (type(10**5))  # int

Int 在 python 中可以变得任意大.. float ...没有那么多。

You are using different types

print (type(1e5))    # float
print (type(10**5))  # int

Int can get arbitrarily big in python .. float ... not so much.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文