Numeric comparison anomaly

paul m pmagwene at speakeasy.net
Wed Feb 19 14:32:48 CET 2003


"Klaus Alexander Seistrup" <spam at magnetic-ink.dk> wrote in message
news:50e6834f-5285-4b01-9e51-de322339becc at news.szn.dk...

>
> Python has builtin infinity:
>
> #v+
>
> $ python
> Python 2.2.2 (#1, Jan 18 2003, 10:18:59)
> [GCC 3.2.2 20030109 (Debian prerelease)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> Welcome to rlcompleter2 0.95
> for nice experiences hit <tab> multiple times
> >>> infinity = float('Inf')
> >>> infinity < 9
> 0
> >>> infinity > 99999
> 1
> >>> 99999 < infinity
> 1
> >>> infinity >= 3
> 1
> >>> ^D
> $
>
> #v-
>
> You can use "float('-Inf')" and "float('NaN')", too.
>

Unfortunately, that's entirely platform specific.  Neither of the two
platforms I have here at home support float('Inf'), as shown below...

On Win2k:

Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> infinity = float('Inf')
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in ?
    infinity = float('Inf')
ValueError: invalid literal for float(): Inf
>>>

On FreeBSD:

[GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> infinity = float('Inf')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for float(): Inf
>>>

--Paul





More information about the Python-list mailing list