Boost C++ Libraries: Ticket #8326: returned value of pow() is wrong if argument-variable is reused to accept. https://svn.boost.org/trac10/ticket/8326 <p> If argument-variable is reuse directly, pow(2, 10) returns 1.<br /> Sample code is the following. </p> <pre class="wiki"> #include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;boost/math/special_functions/beta.hpp&gt; #include &lt;boost/multiprecision/cpp_dec_float.hpp&gt; int main() { typedef boost::multiprecision::number&lt;boost::multiprecision::cpp_dec_float&lt;50&gt; &gt; MY_FLOAT_TYPE; const double var1 = 2; const double var2 = 10; // OK (equal to 1024) { MY_FLOAT_TYPE a = var1; MY_FLOAT_TYPE b = var2; MY_FLOAT_TYPE c = pow(a, b); std::cout &lt;&lt; "result1=" &lt;&lt; c &lt;&lt; std::endl; a = c; // reusing variable 'a' indirectly. std::cout &lt;&lt; "result2=" &lt;&lt; a &lt;&lt; std::endl; } // NG (not equal to 1024) { MY_FLOAT_TYPE a = var1; MY_FLOAT_TYPE b = var2; a = pow(a, b); // reusing variable 'a' directly. std::cout &lt;&lt; "result3=" &lt;&lt; a &lt;&lt; std::endl; } return 0; } </pre><p> Output is the following. </p> <pre class="wiki">result1=1024 result2=1024 result3=1 </pre><p> Incidentally, output of pow(2, 0.5) is the following. Similar problem happened. </p> <pre class="wiki">result1=1.41421 result2=1.41421 result3=1.18921 </pre><p> I found this problem on Visual Studio 2010 and Linux gcc 4.4.7.<br /> I found similar problem with <strong>mpf_float</strong> on Linux gcc 4.4.7.<br /> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8326 Trac 1.4.3 John Maddock Thu, 28 Mar 2013 11:27:11 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8326#comment:1 https://svn.boost.org/trac10/ticket/8326#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/83619" title="Fix bug(s) that cause variable reuse in function calls to fail. Add ...">[83619]</a>) Fix bug(s) that cause variable reuse in function calls to fail. Add additional test cases. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8326" title="#8326: Bugs: returned value of pow() is wrong if argument-variable is reused to accept. (closed: fixed)">#8326</a>. </p> Ticket John Maddock Sun, 31 Mar 2013 16:34:53 GMT <link>https://svn.boost.org/trac10/ticket/8326#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8326#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/83669" title="Merge fix for #8326, plus misc valgrind errors. Refs #8326.">[83669]</a>) Merge fix for <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8326" title="#8326: Bugs: returned value of pow() is wrong if argument-variable is reused to accept. (closed: fixed)">#8326</a>, plus misc valgrind errors. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8326" title="#8326: Bugs: returned value of pow() is wrong if argument-variable is reused to accept. (closed: fixed)">#8326</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>