How to represent the infinite ?

Tim Peters tim.one at comcast.net
Fri Jun 21 01:19:50 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).

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






More information about the Python-list mailing list