gmpxxll.hpp#

long long support for mpz_class. This file provides gmpxll::mpz_class which inherits from the official mpz_class and is binary compatible with it.

This makes it possible to mix the two types quite freely. So, you might want to use gmpxxll::mpz_class where you perform (generic) conversion from/to standard integer types and use the regular mpz_class everywhere else:

#include "gmpxxll/mpz_class.hpp"

mpz_class n;
gmpxxll::mpz_class m = std::limits<long long>::max;

// Since gmpxxll::mpz_class is derived from mpz_class, it casts implicitly into it:
n = m;

// Conversely, there are explicit conversions:
m = n;
m = gmpxxll::mpz_class(n);

class mpz_class : public mpz_class#

Adds long long functionality to mpz_class. This class derives from GMP’s mpz_class. It is binary compatible with that class but adds some methods related to long long and unsigned long / long. Note that on LP64 implementations of C++ both long and long long are 64 bits wide so this does not add anything and performance overhead should be negligible when optimizations are enabled. On LLP64 implementations, most notably Microsoft Windows, conversions actually need to take place. These conversions are probably not implemented very efficiently yet.

mpz_class(…)

Construct an mpz_class from an (unsigned) long long value. All the constructors provided by GMP’s mpz_class are also available through a forwarding constructor.

inline mpz_class(long long value)#
inline mpz_class(unsigned long long value)#

Type Conversion

Return this integer as an (unsigned) long long value. The behaviour is undefined when the integer does not fit into an (unsigned) long long.

inline long long get_sll() const#
inline unsigned long long get_ull() const#

Range Checks

Return whether this integers is within the range of an (unsigned) long long.

inline bool fits_slonglong_p() const#
inline bool fits_ulonglong_p() const#