Backporting float ("inf") in Python 2.4 and 2.5

I am transferring my project from Python 2.6 to Python 2.4 and 2.5. I used in my project float("inf"), and now I believe that it is not available in Python 2.5. Is there a rear port?

+3
source share
5 answers

I created backport, tested on Python 2.5+, it might work easily on Python 2.4:

https://github.com/cool-RR/GarlicSim/blob/master/garlicsim/garlicsim/general_misc/infinity.py

0
source

Writing this either a long or short path is great for me:

$ python2.4 -c "print float('inf')+200"
inf
$ python2.5 -c "print float('inf')+200"
inf
$ python2.5 -c "print float('infinity')+200"
inf
$ python2.4 -c "print float('infinity')+200"
inf

The flag -cmeans "execute the following arguments as a Python command."

PEP754 ( ) IEEE-754. - 1e300000 inf, , .

+5

, Python . :

>>> 1e100000
inf
>>> float('inf') == 1e1000000
True
>>> float('inf') == 2e1000000
True
+2

decimal Python 2.4 . float (, , float ), , .

>>> decimal.Decimal('Infinity') > 1e300
True
+1

NumPy :

import numpy as np

inf = float(np.inf)

inf python float, NumPy.

0

Source: https://habr.com/ru/post/1719785/


All Articles