how to compare two infinitely large numbers in python

Viewed 77

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?

1 Answers

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".

Related