Python中的最大浮点数是多少?

发布于 2024-09-14 13:31:30 字数 172 浏览 1 评论 0原文

Python 2 中的最大整数可通过调用 sys.maxint 获得。

Python 中的最大浮点数或长整数是多少?


另请参阅:整数的最大值和最小值

The maximum integer in Python 2 is available by calling sys.maxint.

What is the maximum float or long in Python?


See also: Maximum and Minimum values for ints.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

旧伤慢歌 2024-09-21 13:31:30

对于float,请查看sys .float_info

>>> import sys
>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, 
min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, 
epsilon=2.220446049250313e-16, radix=2, rounds=1)

具体来说,sys.float_info.max

>>> sys.float_info.max
1.7976931348623157e+308

如果不够大,总是有正无穷

>>> infinity = float("inf")
>>> infinity
inf
>>> infinity / 10000
inf

int 具有无限的精度,因此它仅受可用内存的限制。

For float have a look at sys.float_info:

>>> import sys
>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, 
min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, 
epsilon=2.220446049250313e-16, radix=2, rounds=1)

Specifically, sys.float_info.max:

>>> sys.float_info.max
1.7976931348623157e+308

If that's not big enough, there's always positive infinity:

>>> infinity = float("inf")
>>> infinity
inf
>>> infinity / 10000
inf

int has unlimited precision, so it's only limited by available memory.

心欲静而疯不止 2024-09-21 13:31:30

sys.maxsize(以前的sys.maxint)不是Python支持的最大整数。它是 python 常规整数类型支持的最大整数。

sys.maxsize (previously sys.maxint) is not the largest integer supported by python. It's the largest integer supported by python's regular integer type.

奢望 2024-09-21 13:31:30

如果您使用 numpy,则可以使用 dtype 'float128' 并获得最大浮点数 10e+4931

>>> np.finfo(np.float128)
finfo(resolution=1e-18, min=-1.18973149536e+4932, max=1.18973149536e+4932, dtype=float128)

If you are using numpy, you can use dtype 'float128' and get a max float of 10e+4931

>>> np.finfo(np.float128)
finfo(resolution=1e-18, min=-1.18973149536e+4932, max=1.18973149536e+4932, dtype=float128)
云仙小弟 2024-09-21 13:31:30

在 python 3 中没有 sys.maxint
有一个sys.maxsize

>>> sys.maxsize
2147483647

并不意味着将最大int限制为20亿!
这意味着包含整数的对象的大小最大为 20 亿字节。即一个非常非常大的数字

对于float,请查看sys.float_info

>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

,特别是sys.float_info.max

>>> sys.float_info.max
1.7976931348623157e+308

In python 3 there is no sys.maxint
There is a sys.maxsize

>>> sys.maxsize
2147483647

That does not mean that the maximum int is limited to 2 billion!
It means that the size of the object containing the integer has a maximum size of 2 billion bytes. I.e. a very very large number

For float have a look at sys.float_info

>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

And specifically sys.float_info.max

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