boost::multiprecision : How to convert a mpz_int variable to gmp_int?

1k Views Asked by At

I have converted a mpz_int to gmp_int by converting a mpz_int to mpz_class and then converting the mpz_class instance to a gmp_int. Is there an easier way to do it ? thanks

2

There are 2 best solutions below

3
On

From the tutorial and documentation, there is a member function backend() in mpz_int that gives access to the underlying gmp_int.

1
On

For me, the convert_to<> method seems to work: Live On Coliru

#include <boost/multiprecision/mpfr.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

int main()
{
    cpp_int i;
    mpz_int z;

    i = z.convert_to<cpp_int>();
}