find all multiplicands and multipliers for a number

Dave Angel davea at
Mon Apr 13 06:35:02 CEST 2015

On 04/12/2015 11:30 PM, Paul Rubin wrote:
> Dave Angel <davea at> writes:
>> If I were trying to get a bound for stopping the divide operation, on
>> a value too large to do exact real representation, I'd try doing just
>> a few iterations of Newton's method.
> Python ninja trick: math.log works on bignums too large to be
> represented as floats ;-)

But doesn't math.pow return a float?   Af first crack I figured it was 
because I had supplied math.e as the first argument.  But I have the 
same problem with  (python 3.4)

x = 2596148429267413814265248164610047
print( math.pow(2, math.log2(x)) )

Or were you saying bignums bigger than a float can represent at all?  Like:

 >>> x = 2**11111 -1
 >>> len(str(x))
 >>> math.log2(x)
 >>> math.pow(2, math.log2(x)//2)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
OverflowError: math range error


More information about the Python-list mailing list