FLINT3.7.0-dev

fmpq_gcd, _fmpq_gcd

Synopsis#include <flint/fmpq.h>
void fmpq_gcd(fmpq_t res, const fmpq_t op1, const fmpq_t op2)source
void _fmpq_gcd(fmpz_t rnum, fmpz_t rden, const fmpz_t p, const fmpz_t q, const fmpz_t r, const fmpz_t s)source

Set the result to the GCD of p/q and r/s, defined as the canonicalisation of \gcd(ps, qr)/(qs). For canonical inputs this is \gcd(p, r)/\operatorname{lcm}(q, s), the largest rational g such that p/q and r/s are both integer multiples of g; it is nonnegative, and zero only if both inputs are zero.

This definition is invariant under scaling numerator and denominator, agrees with the GCD on the integers, and gives the same results as Sage and PARI/GP. It is not the GCD of fmpq_poly, where the GCD of nonzero constants is 1.

_fmpq_gcd does not require canonical inputs, but the denominators must be nonzero.

Guides#

Cite this page

The FLINT team, “fmpq_gcd, _fmpq_gcd (fmpq.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fmpq/fmpq_gcd.html (generated 2026-10-20).