I've spent the better part of the day tracking a problem down to this example:
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>
int main ()
{
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>> float_t;
//typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::expression_template_option::et_off> float_t; // <--- this works ok, too!
float_t dependency = 2.0;
auto const val = dependency / 2;
//float_t const val = dependency / 2; // <--- this works ok!
std::cout << val << std::endl;
dependency = val - 2;
std::cout << val << std::endl;
dependency = val - 2;
std::cout << val << std::endl;
dependency = val - 2;
return 0;
}
outputs
1
-0.5
-1.25
It seems as though the dependency of val on dependency breaks the const promise.
Changing the auto const to float_t const fixes the problem.
Using cpp_bin_float fixes the problem
On random suspicion, disabling expression templates fixes the problem
This occurs on multiple VS versions, mingw8.1, and Coliru.
Could anyone more familiar with the internal workings explain what is going on?