[Edu-sig] Exponentiation should float

Greg Ward gward@cnri.reston.va.us
Tue, 15 Feb 2000 17:24:18 -0500

On 15 February 2000, Bruce Sherwood said:
> The problem is that exponentiation goes, well, exponential. So it is real
> easy for this operation to give a result too large even for long integers.
> A more general statement would be that if there is overflow on integer
> exponentiation, the operation should be repeated with a floating result.

Arrgghh, here we go again with another geek thread.  But, being a geek,
I just have to jump in: the whole point of long integers is that they
*can't* overflow.  I just got Python to compute 2**50000, and after a
noticeable delay it spat back a several-thousand-digit number at me.
Given enough time, I expect it could calculate 2**(2**50000)
... ummm... I'm doing it now, and it looks like there's no memory leak,
so it probably *could* do it.  I'll get back to you in a few years with
the result.  ;-)

Anyways, there's no way you could do that with floating point math.  You
run out of accuracy much faster with floats than with long ints.  So
your argument is backwards: exponentiation of integers wants to fallback
to longints when the result gets too big for ints, because floats don't
have enough bits either.

Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                           voice: +1-703-620-8990
Reston, Virginia, USA  20191-5434                    fax: +1-703-620-0913