[英]how to compare two infinitely large numbers in python
I am creating an algorithm where a metric may take 3 values:我正在创建一个算法,其中一个指标可能采用 3 个值:
Now, math.inf
handles the infinite.现在, math.inf
处理无限。
The result of the third value has no determined borders.第三个值的结果没有确定的边界。 But, I want the second value to be always smaller than infinite and always larger than the third value.但是,我希望第二个值始终小于无限且始终大于第三个值。 Therefore I cannot give it some very large number like 999999999999999
since there is always a possibility that the calculation may exceed it.因此我不能给它一些非常大的数字,比如999999999999999
,因为计算总是有可能超过它。
What I am looking for is another constant like Ellipsis
of Python 2.我正在寻找的是另一个常数,例如 Python 2 的Ellipsis
。
How can I make this happen?我怎样才能做到这一点?
You can try sys.float_info.max
:您可以尝试sys.float_info.max
:
>>> import sys
>>> sys.float_info.max
1.7976931348623157e+308
According to the documentation , it's the "maximum representable positive finite float".根据文档,它是“最大可表示的正有限浮点数”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.