Python中的无限整数 [英] Infinite integer in Python

查看:178
本文介绍了Python中的无限整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 3具有float('inf')Decimal('Infinity'),但没有int('inf').那么,为什么在语言中缺少代表无限整数集的数字呢? int('inf')不合理吗?

Python 3 has float('inf') and Decimal('Infinity') but no int('inf'). So, why a number representing the infinite set of integers is missing in the language? Is int('inf') unreasonable?

推荐答案

来自此处:

IEEE 754浮点数可以表示正无穷大或NaN(不是数字)

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

即,floatDecimal的表示形式可以存储这些特殊值.但是,基本类型int中没有任何东西可以存储相同的内容.当您在无符号的32位int中超出2 ^ 32的限制时,只需简单地再次翻转到0.

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.

这篇关于Python中的无限整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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