Difference between the Python built-in pow and math pow for large integers
<p>I find that for large integers, the math.pow does not successfully translate to its integer version. I got a buggy <a href="https://en.wikipedia.org/wiki/Karatsuba_algorithm" rel="nofollow">Karatsuba multiplication</a> when implemented with math.pow. </p>

<p>For instance:</p>

<pre><code>&gt;&gt;&gt; a_Size=32
&gt;&gt;&gt; pow(10,a_size) * 1024
102400000000000000000000000000000000
&gt;&gt;&gt; math.pow(10,a_size) * 1024
1.024e+35
&gt;&gt;&gt; int(math.pow(10,a_size) * 1024)
102400000000000005494950097298915328
</code></pre>

<p>I went with 10 ** a_size with correct results for large integers.</p>

<p>For floats, visit <a href="http://stackoverflow.com/questions/10282674/difference-between-the-built-in-pow-and-math-pow-for-floats-in-python">Difference between the built-in pow() and math.pow() for floats, in Python?</a></p>

<p>Please explain why this discrepancy is seen for math.pow. It is observed only from 10 power of 23 and higher.</p>

<p><code>math.pow()</code> always returns a floating-point number, so you are limited by the precision of <code>float</code> (almost always an IEEE 754 double precision number).  The built-in <code>pow()</code> on the other hand will use Python's arbitrary precision integer arithmetic when called with integer arguments.</p>

python math largenumber karatsuba