Python-如何确定系统可以处理的最大/最小int/long/float/complex数字 [英] Python-How to determine largest/smallest int/long/float/complex numbers my system can handle

查看:190
本文介绍了Python-如何确定系统可以处理的最大/最小int/long/float/complex数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

规格: Python 3.3.1

Specs: Python 3.3.1

我正在尝试做的事情:使用Python,确定系统可以处理的最大和最小整数,整数,浮点数和复数."

What I was trying to do: "Using Python, determine the largest and smallest ints, longs, floats, and complex numbers that your system can handle."

我的工作:我遍历了Python的数学模块以及与数学和数字有关的所有内置函数,但找不到解决方法.我也尝试了类似max(range(0,))的方法,但是它返回了ValueError: max() arg is an empty sequence错误.

What I did: I went through Python's math modules and all built-in functions relating to math and numbers, but couldn't find a way to do this. I also tried something like max(range(0,)) but it returned ValueError: max() arg is an empty sequence error.

问题:如何确定系统可以使用Python处理的最大/最小int/long/float/complex数字?作为一个初学者,我知道我一定错过了一些东西,但是我尝试了一下,却无法解决.我感谢您的帮助!

Question: How to determine largest/smallest int/long/float/complex numbers my system can handle using Python? As a total beginner, I know I must have missed something, but I tried and wasn't able to figure it out. I appreciate your help!

推荐答案

  • sys.float_info 是具有浮点数限制的命名元组为您的平台.浮点数由指数和精度组成.您必须更精确地了解此处最大的数字的含义;指数最大且使用时的完整精度为sys.float_info.max.

    sys.int_info ;没有太多的限制,只是实现细节;您应该能够据此估算出最大的整数. Python整数仅受可用内存的限制.

    sys.int_info; not so much limitations as the implementation detail; you should be able to estimate the largest integer possible from this. Python integers are only limited by your available memory.

    sys.maxsize ;平台字的大小以及对列表和元组等的限制.

    sys.maxsize; the platform word size and limit to lists and tuples and the likes.

    因此对于整数,最大值和最小值基本上都有一个 soft 限制.这取决于您的进程可以使用多少内存,以及您的进程已经为其他用途使用了多少内存.

    So for integers, there basically is a soft limit to the maximum and minimum values. It depends on how much memory your process can use, and how much memory your process is already using for other things.

    在Python 3中,不再有单独的long类型,但是在Python 2中,sys.maxsize + 1-sys.maxsize - 2一样必须是long.在这两个极端之间是可能的短"整数范围.

    In Python 3, there no longer is a separate long type, but in Python 2, sys.maxsize + 1 would have to be a long, as would -sys.maxsize - 2. Between those two extremes lies the range of possible 'short' integers.

    对于复数,排序要复杂得多.复数具有实部和虚部,都是浮点数.你猜怎么了?这些是python浮点数,您已经在上方有了其限制信息:

    For complex numbers, ordering is a little more.... complex anyway. Complex numbers have a real and imaginary component, both are floats. Guess what? These are python floats and you already have their limit info above:

    >>> type(1j)
    <type 'complex'>
    >>> type(1j.real)
    <type 'float'>
    >>> type(1j.imag)
    <type 'float'>
    

    这篇关于Python-如何确定系统可以处理的最大/最小int/long/float/complex数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆