[Boost-bugs] [Boost C++ Libraries] #8326: returned value of pow() is wrong if argument-variable is reused to accept.

Subject: [Boost-bugs] [Boost C++ Libraries] #8326: returned value of pow() is wrong if argument-variable is reused to accept.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-03-22 18:41:38


#8326: returned value of pow() is wrong if argument-variable is reused to accept.
------------------------------+---------------------------------------------
 Reporter: pjtsu | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: multiprecision
  Version: Boost 1.53.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 If argument-variable is reuse directly, pow(2, 10) returns 1.[[BR]]
 Sample code is the following.

 {{{

 #include <iostream>
 #include <iomanip>
 #include <boost/math/special_functions/beta.hpp>
 #include <boost/multiprecision/cpp_dec_float.hpp>

 int main()
 {
         typedef
 boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50> >
 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 << "result1=" << c << std::endl;
                 a = c; // reusing variable 'a' indirectly.
                 std::cout << "result2=" << a << 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 << "result3=" << a << std::endl;
         }

         return 0;
 }

 }}}

 Output is the following.
 {{{
 result1=1024
 result2=1024
 result3=1
 }}}

 Incidentally, output of pow(2, 0.5) is the following. Similar problem
 happened.
 {{{
 result1=1.41421
 result2=1.41421
 result3=1.18921
 }}}

 I found this problem on Visual Studio 2010 and Linux gcc 4.4.7.[[BR]]
 I found similar problem with '''mpf_float''' on Linux gcc 4.4.7.[[BR]]

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8326>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC