How to represent the infinite ?

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Fri Jun 21 13:25:25 EDT 2002


>[Christophe Delord]
>> ...
>> >>> 1e200**2
>> Traceback (most recent call last):
>>   File "<pyshell#1>", line 1, in ?
>>     1e200**2
>> OverflowError: (34, 'Numerical result out of range')
>> >>> 1e400
>> inf
>>
>> When the overflow occurs, the OverflowError exception is thrown.
>> inf can't be the result of a computation (without patch and
>> without catching exception).

The patch is in fact very simple: just remove the extra code whose sole
purpose is to throw an exception.   No patch to catch the exception is
needed.  

Tim Peters <tim.one at comcast.net> wrote:
>
>It can, but it's a x-platform crapshoot as to exactly how.  For example,
>under current Windows CVS, this still "works":
>
>>>> 1e300 * 1e300
>1.#INF
>>>>
>
>Here's a clumsier way <wink>:
>
>>>> 1.6e308 + 1.6e308
>1.#INF
>>>>
>
>Both of those assume the user hasn't installed and enabled the fpectl
>module, whose purpose in life is to cause even this to complain.
>
>maybe-number-crunchers-will-agree-on-something-after-i'm-dead-
>    but-i'm-not-holding-my-breath-ly y'rs  - tim

Now I'm confused.  I thought from previous discussions that you intended to
disable inf and nan until full ieee floating point compliance is implemented
in Python.  And I infered that that's in order to make Windows work.

Since it could be made to work on Linux, I simply commented out the checking
in pyport.h.  Voila, instant ieee compliance!

Your example appears to show that Windows can also live with nan and inf.
So my question is, are there any significant platforms out there that still
really need such checkings which make nan and inf almost useless?

If, in reality, only some very niche platforms need such checkings, maybe it
is better to let those platforms without ieee compliance suffer (in terms of
having to add a small patch), rather than depriving most of the mainstream
platforms of a very useful feature?

I'm looking forward to the day when I don't need to patch Python when a new
version comes out.

Huaiyu




More information about the Python-list mailing list