Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#8326 closed Bugs (fixed)

returned value of pow() is wrong if argument-variable is reused to accept.

Reported by: pjtsu Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:


If argument-variable is reuse directly, pow(2, 10) returns 1.
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.


Incidentally, output of pow(2, 0.5) is the following. Similar problem happened.


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

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by John Maddock

Resolution: fixed
Status: newclosed

(In [83619]) Fix bug(s) that cause variable reuse in function calls to fail. Add additional test cases. Fixes #8326.

comment:2 Changed 5 years ago by John Maddock

(In [83669]) Merge fix for #8326, plus misc valgrind errors. Refs #8326.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain John Maddock.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.