Class Gmp.mpz


Gmp.mpz implements very large integers. In fact, the only limitation on these integers is the available memory. The mpz object implements all the normal integer operations.

Note that the auto-bignum feature also makes these operations available "in" normal integers. For instance, to calculate the greatest common divisor between 51 and 85, you can do 51->gcd(85).

Method create

Gmp.mpz Gmp.mpz()
Gmp.mpz Gmp.mpz(string|int|float|object value)
Gmp.mpz Gmp.mpz(string value, int(2..36)|int(256)|int(-256) base)


Create and initialize a Gmp.mpz object.

Parameter value

Initial value. If no value is specified, the object will be initialized to zero.

Parameter base

Base the value is specified in. The default base is base 10. The base can be either a value in the range [2..36] (inclusive), in which case the numbers are taken from the ASCII range 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ (case-insensitive), or either of the values 256 or -256, in which case value is taken to be the unsigned binary representation in network byte order or reversed byte order respectively.

Values in base [2..36] can be prefixed with "+" or "-". Values prefixed with "0b" or "0B" will be interpreted as binary. Values prefixed with "0x" or "0X" will be interpreted as hexadecimal. Values prefixed with "0" will be interpreted as octal.


Leading zeroes in value are not significant when a base is explicitly given. In particular leading NUL characters are not preserved in the base 256 modes.