I use Boost.Multiprecision to wrap around the mpfr backend, and I'm having trouble creating pi (and e or any other math constant) for my desired accuracy. I feel that what I want to do should be possible due to the use of Boost.Math for constants on the tutorial page for Boost.Multiprecision . In the tutorial, they use fixed-type numbers such as cpp_dec_float_50 - I want to do this using mpfr_float variable mpfr_float . Check out the following code:
#include <boost/multiprecision/mpfr.hpp> #include <boost/math/constants/constants.hpp> #include <iostream> ... int main() { boost::multiprecision::mpfr_float::default_precision(1000); boost::multiprecision::mpfr_float pi = boost::math::constants::pi<boost::multiprecision::mpfr_float>(); std::cout << std::fixed; std::cout.precision(1000); std::cout << pi.precision() << " " << pi << std::endl; }
The result is a number, pi , which has an accuracy of 1000 but only ~ 165 digits of pi, as evidenced by the result of the output statements, which confirm that my pi has an accuracy of 1000, and prints about 165 correct digits and ~ 835 zeros. this is clearly wrong.
is it possible to make boost :: multiprecision :: mpfr_float with high precision filled with constants from boost :: math :: constants?
Please note that I need to use a variable precision type and that other types with a high degree of precision are not an option. I should be able to change accuracy on the fly at runtime.
source share