Infinite integer in Python

后端 未结 3 1482
耶瑟儿~
耶瑟儿~ 2021-02-11 12:06

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:40

    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.

提交回复
热议问题