Why is pow(int, int) so slow?
<p>I've been working on a few project Euler exercises to improve my knowledge of C++.</p>

<p>I've written the following function:</p>

<pre><code>int a = 0,b = 0,c = 0;

for (a = 1; a &lt;= SUMTOTAL; a++)
{
    for (b = a+1; b &lt;= SUMTOTAL-a; b++)
    {
        c = SUMTOTAL-(a+b);

        if (c == sqrt(pow(a,2)+pow(b,2)) &amp;&amp; b &lt; c)
        {
            std::cout &lt;&lt; "a: " &lt;&lt; a &lt;&lt; " b: " &lt;&lt; b &lt;&lt; " c: "&lt;&lt; c &lt;&lt; std::endl;
            std::cout &lt;&lt; a * b * c &lt;&lt; std::endl;
        }
    }
}
</code></pre>

<p>This computes in 17 milliseconds.</p>

<p>However, if I change the line</p>

<pre><code>if (c == sqrt(pow(a,2)+pow(b,2)) &amp;&amp; b &lt; c)
</code></pre>

<p>to </p>

<pre><code>if (c == sqrt((a*a)+(b*b)) &amp;&amp; b &lt; c)
</code></pre>

<p>the computation takes place in 2 milliseconds. Is there some obvious implementation detail of <code>pow(int, int)</code> that I'm missing which makes the first expression compute so much slower?</p>