Tim Peters tim.peters at
Sun Jun 11 21:58:42 CEST 2006

[Wojciech Muła]
>> You have to use operator **, i.e. 34564323**456356

Or the builtin pow() instead of math.pow().

[Gary Herron]
> 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).

On my box it took less than 30 seconds to do

    x = 34564323**456356

If you try to _display_ that as a decimal string, it will take
enormously longer.  Python uses a power-of-2 base internally, and
conversion to decimal takes time quadratic in the number of digits.
Doing y = hex(x) instead is very fast (small fraction of a second).

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

For example, if you only want the last 6 digits, pow(34564323, 456356,
1000000) returns 986961 in an eyeblink.

More information about the Python-list mailing list