math.pow(x,y)
Raymond L. Buvel
levub137 at wi.rr.com
Sun Jun 11 15:33:41 EDT 2006
Felipe Almeida Lessa wrote:
> Em Dom, 2006-06-11 às 11:19 -0700, fl1p-fl0p escreveu:
>> import math
>> math.pow(34564323, 456356)
>>
>> will give math range error.
>>
>> how can i force python to process huge integers without math range
>> error? Any modules i can use possibly?
>
> 34564323**456356 ?
>
I just tried this and it is taking an extremely long time even on a fast
machine with 4 Gb of RAM. Killed it after a couple of minutes. This
sort of calculation can be done with extended precision floating point
(as long as you don't need an exact answer). For example (using
defaults on a 64-bit machine),
>>> from clnum import mpf
>>> mpf(34564323)**456356
mpf('1.39518106833639480699862472257296396643e3440298',36)
compute time is about 160 microseconds.
For more information see
http://calcrpnpy.sourceforge.net/clnumManual.html
For calculations involving large powers, you may still be better off
using logarithms.
More information about the Python-list
mailing list