Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

gmp_int

#include <boost/multiprecision/gmp.hpp>

namespace boost{ namespace multiprecision{

class gmp_int;

typedef number<gmp_int >         mpz_int;

}} // namespaces

The gmp_int back-end is used via the typedef boost::multiprecision::mpz_int. It acts as a thin wrapper around the GMP mpz_t to provide an integer type that is a drop-in replacement for the native C++ integer types, but with unlimited precision.

As well as the usual conversions from arithmetic and string types, type mpz_int is copy constructible and assignable from:

It's also possible to access the underlying mpz_t via the data() member function of gmp_int.

Things you should know when using this type:

Example:
#include <boost/multiprecision/gmp.hpp>
#include <iostream>

int main()
{
   using namespace boost::multiprecision;

   mpz_int v = 1;

   // Do some arithmetic:
   for(unsigned i = 1; i <= 1000; ++i)
      v *= i;

   std::cout << v << std::endl; // prints 1000!

   // Access the underlying representation:
   mpz_t z;
   mpz_init(z);
   mpz_set(z, v.backend().data());
   mpz_clear(z);
   return 0;
}

PrevUpHomeNext