How to represent the infinite ?

Christophe Delord christophe.delord at free.fr
Thu Jun 20 19:32:30 CEST 2002


There is another simple solution. Just use a float that is bigger than any 64-bit float. For example 10^1000. This float has a special encoding meaning +oo !
So no need to redefine anything else ;-)

>>> x=1e1000
>>> x
inf
>>> x>10
True
>>> x<10
False
>>> 10>x
False
>>> 10<x
True
>>> x-x
nan
>>> -x
-inf

Warning: +oo==+oo so don't be surprised by this example:

>>> 1e1000==1e2000
True


Christophe.


> Not need to say to me that I can use 99999999999999 or -99999999999999 or I
> do not know what.
> Nor from a MAX_INT of the machine... bus Python can go higher.
> 




-- 

(o_   Christophe Delord                   _o)
//\   http://christophe.delord.free.fr/   /\\
V_/_  mailto:christophe.delord at free.fr   _\_V



More information about the Python-list mailing list