Deprecated since release 2.2.
See the references at the end of this section for
information about packages which provide similar
functionality. This module will be removed in Python
2.3.
This is an optional module. It is only available when Python is
configured to include it, which requires that the GNU MP software is
installed.
This module implements the interface to part of the GNU MP library,
which defines arbitrary precision integer and rational number
arithmetic routines. Only the interfaces to the integer
(mpz_*()) routines are provided. If not stated
otherwise, the description in the GNU MP documentation can be applied.
Support for rational numberscan be
implemented in Python. For an example, see the
Rat module, provided as
Demos/classes/Rat.py in the Python source distribution.
In general, mpz-numbers can be used just like other standard
Python numbers, e.g., you can use the built-in operators like +,
*, etc., as well as the standard built-in functions like
abs(), int(), ..., divmod(),
pow(). Please note: the bitwise-xor
operation has been implemented as a bunch of ands,
inverts and ors, because the library lacks an
mpz_xor() function, and I didn't need one.
You create an mpz-number by calling the function mpz() (see
below for an exact description). An mpz-number is printed like this:
mpz(value).
Create a new mpz-number. value can be an integer, a long,
another mpz-number, or even a string. If it is a string, it is
interpreted as an array of radix-256 digits, least significant digit
first, resulting in a positive number. See also the binary()
method, described below.
Return pow(base, exponent) % modulus. If
exponent == 0, return mpz(1). In contrast to the
C library function, this version can handle negative exponents.
This project is building new numeric types to allow
arbitrary-precision arithmetic in Python. Their first
efforts are also based on the GNU MP library.