Generic Functions

gmpy2.add(x, y, /) mpz | mpq | mpfr | mpc

Return x + y.

gmpy2.div(x, y, /) mpz | mpq | mpfr | mpc

Return x / y; uses true division.

gmpy2.mul(x, y, /) mpz | mpq | mpfr | mpc

Return x * y.

gmpy2.sub(x, y, /) mpz | mpq | mpfr | mpc

Return x - y.

gmpy2.square(x, /) mpz | mpq | mpfr | mpc

Return x * x.

gmpy2.f2q(x, err=0, /) mpz | mpq

Return the ‘best’ mpq approximating x to within relative error err. Default is the precision of x. Uses Stern-Brocot tree to find the ‘best’ approximation. An mpz object is returned if the denominator is 1. If err<0, relative error is 2.0 ** err.

gmpy2.fma(x, y, z, /) mpz | mpq | mpfr | mpc

Return correctly rounded result of (x * y) + z.

gmpy2.fms(x, y, z, /) mpz | mpq | mpfr | mpc

Return correctly rounded result of (x * y) - z.

gmpy2.cmp_abs(x, y, /) int

Return -1 if abs(x) < abs(y); 0 if abs(x) = abs(y); or 1 else.