I need to do calculations with higher precision than doubles and am using boost::multiprecision for that. This works perfectly fine when I use boost::multiprecision::cpp_bin_float_50
or boost::multiprecision::cpp_bin_float_100
. So simply doing something like
#include <boost/multiprecision/cpp_bin_float.hpp>
// ...
boost::multiprecision::cpp_bin_float_100 Test1, Test2;
Test1 = 1.0;
Test2 = 2.0;
Test1 = Test1 + Test2;
works. But I need different amounts of precision. So for example, I'd simply like to do something like
boost::multiprecision::cpp_bin_float<200> Test1, Test2;
Test1 = 1.0;
Test2 = 2.0;
Test1 = Test1 + Test2;
While the first three lines work fine, I get an error in the forth line saying "no matching operator found". Also .convert_to<double>()
is not found, which I will need later. Same thing for cpp_dec_float
...
I'm sure, I am missing something stupid here. Can anybody help?
Edit:
Thank you sehe - I just wanted to edit in the exact same thing. It took me ages to find that out. Funny how I couldn't find one single example of how to use arbitrary lengths other than ..._50 or ..._100...
The
boost::multiprecision::cpp_bin_float<200>
type is a backend type. You want a frontend type, which would be e.g.You can compare this with the definitions of the working types:
Backends define the implementation, where the frontend provides the usability interfaces that you expect, like operator overloads.
Live Demo
Prints: