Rationals
mpq type
- class gmpy2.mpq(n=0, /)
- class gmpy2.mpq(n, m, /)
- class gmpy2.mpq(s, /, base=10)
Return a rational number constructed from a non-complex number n exactly or from a pair of
Rationalvalues n and m or from a string s made up of digits in the given base. Every input, that is accepted by theFractiontype constructor is also accepted.A string may be made up to two integers in the same base separated by a ‘/’ character, both parsed the same as the
mpztype constructor does. If base is 0 then the leading characters are used to recognize the base, this is done separately for the numerator and denominator. If base=10, any string that represents a finite value and is accepted by thefloatconstructor is also accepted.- as_integer_ratio()
Return a pair of integers, whose ratio is exactly equal to the original number. The ratio is in lowest terms and has a positive denominator.
- conjugate()
Return the conjugate of self (which is just a new reference to self since self is not a complex number).
- digits(base=10, /)
Return a Python string representing self in the given base (2 to 62, default is 10). A leading ‘-’ is present for negatives.
- classmethod from_decimal(dec, /)
Converts a finite
decimal.Decimalinstance to a rational number, exactly.
- classmethod from_float(f, /)
Converts a finite float to a rational number, exactly.
- limit_denominator(max_denominator=1000000)
Closest fraction to self with denominator at most max_denominator.
- denominator
the denominator of a rational number in lowest terms
- imag
the imaginary part of a complex number
- numerator
the numerator of a rational number in lowest terms
- real
the real part of a complex number