math.pow(x,y)

F

fl1p-fl0p

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?
 
W

Wojciech =?iso-8859-2?Q?Mu=B3a?=

fl1p-fl0p said:
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?

You have to use operator **, i.e. 34564323**456356
 
F

Felipe Almeida Lessa

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 ?
 
G

Gary Herron

Wojciech said:
You have to use operator **, i.e. 34564323**456356
That's not very practical. That computation will produce a value with
more than 3.4 million digits. (That is, log10(34564323)*456356 =
3440298.) Python will attempt this, but I was not patient enough to see
if it could calculate an answer today (or even this week).

I doubt that you really *want* all 3.4 million digits. So what is it you
really want? A scientific or engineering result as a floating point
number accurate to some reasonable number of digits? That integer value
modulo some other integer (as used in various cryptology schemes)?

Gary Herron
 
R

Raymond L. Buvel

Felipe said:
Em Dom, 2006-06-11 às 11:19 -0700, fl1p-fl0p escreveu:

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),
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.
 
K

K.S.Sreeram

Raymond said:
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.

Thats odd.
34564323**456356 completed on my laptop in 28 seconds.
[Python 2.4.3, Celeron-M 1.3GHz, WinXP], and max memory consumption
during the whole process was about 11megs.

What python version are you using?

Regards
Sreeram


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEjHMhrgn0plK5qqURApduAKC5GygYWWtQYTvEyljR9nxW9n+rpACdF2qn
vk5u0zzWoRnfLLkiangJd90=
=zh3g
-----END PGP SIGNATURE-----
 
K

K.S.Sreeram

Raymond said:
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.

You probably tried printing the value.

a = 34564323**456356 (takes just 28 seconds)
whereas
b = str(a) takes forever!

Regards
Sreeram


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEjHWxrgn0plK5qqURAiJGAJ9XYzqDi93YahIvVxqeCs/Ex9ikIQCgnSwu
Eq0mIHCk8o3nvWOllFFXDag=
=BFDh
-----END PGP SIGNATURE-----
 
R

Raymond L. Buvel

K.S.Sreeram said:
Raymond said:
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.

Thats odd.
34564323**456356 completed on my laptop in 28 seconds.
[Python 2.4.3, Celeron-M 1.3GHz, WinXP], and max memory consumption
during the whole process was about 11megs.

What python version are you using?

Regards
Sreeram

Sorry, I tripped over the display problem that Tim Peters has repeatedly
explained on this news group (decimal algorithm is quadratic in the
number of digits) :-(

On a 64-bit 2.2 GHz Opteron running Debian stable, Python 2.3 took 26
seconds and Python 2.4 took 11 seconds.
 
C

casevh

K.S.Sreeram said:
You probably tried printing the value.

a = 34564323**456356 (takes just 28 seconds)
whereas
b = str(a) takes forever!

Regards
Sreeram

If you really want all 3,440,299 digits, use the DecInt module..

http://home.comcast.net/~casevh/

Using Python 2.4.3 on a 1.4Ghz Celeron, a=DecInt(34564323) ** 456356
takes 20 seconds. astr=str(a) takes just over 1 second.

With DecInt and GMPY, the running times are 6.9 seconds and 0.4 seconds
respectively.

casevh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top