简体   繁体   中英

how to compare two infinitely large numbers in python

I am creating an algorithm where a metric may take 3 values:

  • Infinite
  • Too large but not infinite
  • Some number that is the result of a calculation

Now, math.inf handles the infinite.

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.

What I am looking for is another constant like Ellipsis of Python 2.

How can I make this happen?

You can try 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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM