Reputation: 2675
With gmp rationals, do I have the duty to bookkeep my calls to canonicalize()
(which can be costly performance-wise)? Does gmp know that the rational was not changed since the last call to canonicalize()
and will just return if I attempt canonicalization?
I cannot find an answer in the documentation, and maybe someone already looked into the source for this.
Upvotes: 0
Views: 130
Reputation: 37934
It won't likely just return, as mpq_t
does not contain any form of information whether fraction is already in canonical form or not. At least GMP documentation does not mention it as of 16.2 Rational Internals:
mpq_t
variables represent rationals using anmpz_t
numerator and denominator (see Integer Internals).
In practice, it will likely call mpz_gcd()
(or equivalent), to check whether numerator and denominator are coprimes or not.
Upvotes: 0