fmpq_gcd, _fmpq_gcd
#include <flint/fmpq.h>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)sourceSet 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#
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).
@misc{flint-doc-fmpq-fmpq-gcd,
author = {{The FLINT team}},
title = {{fmpq\_gcd, \_fmpq\_gcd (fmpq.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/fmpq/fmpq_gcd.html},
note = {Generated 2026-10-20}
}