Your problem is here:
cpp_dec_float_50 my_num = cpp_dec_float_50(0.123456789123456789123456789); ^
The compiler does not use arbitrary precision floating point literals and instead uses IEEE-754 doubles that have finite precision. In this case, the closest double to the number you wrote:
0.1234567891234567837965840908509562723338603973388671875
And printing it in the 50th decimal decade really gives the result that you are observing.
What you want is to build an arbitrary precision plugin from a string ( demo ):
#include <boost/math/constants/constants.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> #include <iostream> #include <limits> using boost::multiprecision::cpp_dec_float_50; int main() { cpp_dec_float_50 my_num = cpp_dec_float_50("0.123456789123456789123456789"); std::cout.precision(std::numeric_limits<cpp_dec_float_50>::digits10); std::cout << my_num << std::endl; }
Output:
0.123456789123456789123456789
source share