1

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

R Sahu
  • 204,454
  • 14
  • 159
  • 270
user3664264
  • 31
  • 1
  • 3

2 Answers2

2

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

Marc Glisse
  • 7,550
  • 2
  • 30
  • 53
  • 1
    From the documentation, there are a lot more methods. What's your point? – sehe May 23 '14 at 07:58
  • 2
    @sehe The question is "how do I convert from A to B" and the answer was "there is a function f in A", how can you not understand the point, seriously? – Marc Glisse May 23 '14 at 08:08
  • Well I missed the point "that gives access to the underlying `gmp_int`.", mainly because it was missing (zing) and I might have misread the question, as you already noticed. – sehe May 23 '14 at 08:37
0

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>();
}
sehe
  • 374,641
  • 47
  • 450
  • 633