Infinite integer in Python

后端 未结 3 649
再見小時候
再見小時候 2021-02-11 12:15

Python 3 has float(\'inf\') and Decimal(\'Infinity\') but no int(\'inf\'). So, why a number representing the infinite set of integers is m

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-11 12:42

    Taken from here: https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html

    IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number)

    That is, the representation of float and Decimal can store these special values. However, there is nothing within the basic type int that can store the same. As you exceed the limit of 2^32 in an unsigned 32-bit int, you simply roll over to 0 again.

    If you want, you could create a class containing an integer which could feature the possibility of infinite values.

提交回复
热议问题