On 04/12/2015 11:30 PM, Paul Rubin wrote:
Dave Angel <da...@davea.name> 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)) )
2.596148429267414e+33

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

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


--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to