Construct an
mpz_class. All the standard C++ types may be used, exceptlong longandlong double, and all the GMP C++ classes can be used, although conversions frommpq_classandmpf_classareexplicit. Any necessary conversion follows the corresponding C function, for exampledoublefollowsmpz_set_d(see Assigning Integers).
Construct an
mpz_classfrom anmpz_t. The value in z is copied into the newmpz_class, there won't be any permanent association between it and z.
Construct an
mpz_classconverted from a string usingmpz_set_str(see Assigning Integers).If the string is not a valid integer, an
std::invalid_argumentexception is thrown. The same applies tooperator=.
With C++11 compilers, integers can be constructed with the syntax
123_mpzwhich is equivalent tompz_class("123").
Divisions involving
mpz_classround towards zero, as per thempz_tdiv_qandmpz_tdiv_rfunctions (see Integer Division). This is the same as the C99/and%operators.The
mpz_fdiv...ormpz_cdiv...functions can always be called directly if desired. For example,mpz_class q, a, d; ... mpz_fdiv_q (q.get_mpz_t(), a.get_mpz_t(), d.get_mpz_t());
These functions provide a C++ class interface to the corresponding GMP C routines.
cmpcan be used with any of the classes or the standard C++ types, exceptlong longandlong double.
Overloaded operators for combinations of
mpz_class and double
are provided for completeness, but it should be noted that if the given
double is not an integer then the way any rounding is done is currently
unspecified. The rounding might take place at the start, in the middle, or at
the end of the operation, and it might change in the future.
Conversions between mpz_class and double, however, are defined
to follow the corresponding C functions mpz_get_d and mpz_set_d.
And comparisons are always made exactly, as per mpz_cmp_d.