0

I need to compute 5^64 with boost multiprecision library which should yield 542101086242752217003726400434970855712890625 but boost::multiprecision::pow() takes mpfloat and gives 542101086242752217003726392492611895881105408.

However If I loop and repeatedly multiply using mpint I get correct result.

Is it a bug ? or I am using boost::multiprecision::pow() in a wrong way ? or I there is an alternative of using boost::multiprecision::pow() ?

#include <iostream>
#include <string>
#include <boost/multiprecision/gmp.hpp> 

typedef boost::multiprecision::mpz_int mpint;
typedef boost::multiprecision::number<boost::multiprecision::gmp_float<4> > mpfloat;

int main(){
    mpfloat p = boost::multiprecision::pow(mpfloat(5), mpfloat(64));
    std::cout << p.template convert_to<mpint>() << std::endl;

    mpint res(1);
    for(int i = 0; i < 64; ++i){
        res = res * 5;
    }
    std::cout << res << std::endl;
}
Neel Basu
  • 11,848
  • 10
  • 71
  • 138
  • Have you checked the fixed bugs in the relevant releases? http://www.boost.org/doc/libs/1_60_0/libs/multiprecision/doc/html/boost_multiprecision/map/hist.html – sehe Feb 07 '17 at 15:28
  • Don't use gmp_float, see mpfr_float instead. Don't use floats for integer computations. Why `4` in `gmp_float<4>`? – Marc Glisse Feb 07 '17 at 18:49

0 Answers0