How to represent the infinite ?

Christophe Delord christophe.delord at free.fr
Fri Jun 21 12:34:59 EDT 2002


On Fri, 21 Jun 2002 01:19:50 -0400
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.
> 


>>> 1e300
1.0000000000000001e+300
>>> 1e300*1e300
inf
>>> 1e300**2
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in ?
    1e300**2
OverflowError: (34, 'Numerical result out of range')
>>> 

(under Linux with yesterday CVS)

So I was wrong. But addition, multiplication and exponentiation seem to be implemented differently (1e300+1e300 is inf and 1e300**2 is an overflow).
Is there a reason for these different behaviours?


Christophe.


-- 

(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