I am new to Boost.Multiprecision and have come across a result that I cannot understand.
bigint_t b = 2218888517; b = -b;
bigint_t c = 283059965; c = -c;
std::cout << '(' << a << ")^3+(" << b << ")^3+(" << c << ")^3 = ";
bigint_t a1 = a * a * a;
bigint_t b1 = b * b * b;
bigint_t c1 = c * c * c;
std::cout << '(' << a1 << ")+(" << b1 << ")+(" << c1 << ") = ";
std::cout << bigint_t(a1+b1+c1) << '\n';
and it produces the correct result
(2220422932)^3+(-2218888517)^3+(-283059965)^3 = (10947302325566084787191541568)+(-10924622727902378924946084413)+(-22679597663705862245457125) = 30
However, if I use this implementation, with a,b and c assigned the result of the multiplication,
a = a * a * a;
b = b * b * b;
c = c * c * c;
std::cout << '(' << a << ")+(" << b << ")+(" << c << ") = ";
std::cout << bigint_t(a+b+c) << '\n';
... I get a very strange result:
(24307641127223864542936438774018437376)+(24240519923499804093545671548118385521)+(6419686120902663137493915211500625) = 48554580736844571299619604237348323522
What is going on? Is this an invalid use of the multiplication that I have missed?
I get the same result with cpp_int and gmp;
using bigint_t = boost::multiprecision::cpp_int;
using bigint_t = boost::multiprecision::mpz_int;
I'm using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609, Boost 1.58
Many thanks
Craig