How to represent the infinite ?

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


On 20 Jun 2002 17:52:38 GMT
"Donn Cave" <donn at u.washington.edu> wrote:

With Python 2.2 and Linux it works. The example I gave is a copy-paste from IDLE. It also works with my Python 1.5.2 and 2.3 (I'm under Linux on an Intel processor)

So it seems not to be implemented in every binaries and/or platform and/or compiler and/or ... So this solution may not be portable and it may be safer to make a special class for the infinite like in my first reply.

Here is the proof that I'm not totaly drunk yet ;-)

[christ at localhost py]$ python1.5
Python 1.5.2 (#1, Apr  3 2002, 18:16:26)  [GCC 2.96 20000731 (Red Hat Linux 7.2 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> x=1e1000
>>> x
inf
>>>
[christ at localhost py]$ python2.2
Python 2.2 (#1, Apr 12 2002, 15:29:57)
[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x=1e1000
>>> x
inf
>>>
[christ at localhost py]$ python
Python 2.3a0 (#2, Jun 20 2002, 19:48:46)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-110)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x=1e1000
>>> x
inf
>>>
[christ at localhost py]$






> Quoth Christophe Delord <christophe.delord at free.fr>:
> |
> | 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-x
> | nan
> 
> $ python
> Python 2.0 (#1, Dec 18 2000, 10:19:52) [C] on osf1V4
> Type "copyright", "credits" or "license" for more information.
> >>> x = 1e1000
> >>> x
> 1.7976931348623157e+308
> >>> x > 10
> 1
> >>> x - x
> 0.0
> >>>
> 
> I missed the original post, hope this helps.
> 
> 	Donn Cave, donn at u.washington.edu
> 
> | > 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


-- 

(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