Documentation for python-gmp¶
Bindings to the GNU GMP for Python.
- class gmp.mpz(number=0, /)¶
- class gmp.mpz(string, /, base=10)
Convert a number or a string to an integer. If numeric argument is not an int subclass, return mpz(int(number)).
If argument is not a number or if base is given, then it must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
- classmethod from_bytes(bytes, byteorder='big', *, signed=False)¶
Return the integer represented by the given array of bytes.
The argument bytes must either be a bytes-like object or an iterable producing bytes.
The byteorder argument determines the byte order used to represent the integer. Accepted values are ‘big’ and ‘little’, when the most significant byte is at the beginning or at the end of the byte array, respectively.
The signed argument indicates whether two’s complement is used.
- as_integer_ratio()¶
Return a pair of integers, whose ratio is equal to self.
The ratio is in lowest terms and has a positive denominator.
- bit_count()¶
Number of ones in the binary representation of the absolute value of self.
- bit_length()¶
Number of bits necessary to represent self in binary.
- conjugate()¶
Returns self.
- digits(base=10)¶
Return string representing self in the given base.
Values for base can range between 2 to 36.
- is_integer()¶
Returns True.
- to_bytes(length=1, byteorder='big', *, signed=False)¶
Return an array of bytes representing self.
The integer is represented using length bytes. An OverflowError is raised if self is not representable with the given number of bytes.
The byteorder argument determines the byte order used to represent self. Accepted values are ‘big’ and ‘little’, when the most significant byte is at the beginning or at the end of the byte array, respectively.
The signed argument determines whether two’s complement is used to represent self. If signed is False and a negative integer is given, an OverflowError is raised.
- denominator¶
the denominator of self (mpz(1))
- imag¶
the imaginary part of self (mpz(0))
- numerator¶
the numerator of self (the value itself)
- real¶
the real part of self (the value itself)
- gmp.comb(n, k, /)¶
Number of ways to choose k items from n items without repetition and order.
Also called the binomial coefficient.
- gmp.factorial(n, /)¶
Find n!.
- gmp.gcd(*integers)¶
Greatest Common Divisor.
- gmp.isqrt(n, /)¶
Return the integer part of the square root of n.
- gmp.lcm(*integers)¶
Least Common Multiple.
- gmp.perm(n, k=None, /)¶
Number of ways to choose k items from n items without repetition and with order.