mpz_gcd_ext(NULL, ...)
Niels Möller
nisse at lysator.liu.se
Fri Nov 25 11:55:18 UTC 2016
Marc Glisse <marc.glisse at inria.fr> writes:
> a user was asking if we could support calling mpz_gcd_ext with a NULL
> first argument (the gcd), since they are only interested in the
> coefficients s and t and would like to save the unnecessary
> allocation. I doubt it would save that much, but it seems trivial to
> add a check if(g!=NULL) similar to the tests for s and t. Does it make
> sense to you?
Sounds reasonable to me. But then I'd also consider adding a return
value, returning one if the inputs were coprime (gcd == 1), otherwise
zero. Would be useful for mpz_invert.
If we add a return value, for consistency we should do it for mpz_gcd
too, so one could define mpz_coprime_p as
#define mpz_coprime_p(u,v) mpz_gcd (NULL, (u), (v))
(Adding an integer return value is a breaking ABI change in theory, but
not really in practice, as far as I understand).
It won't save much for the computation, only the final copy. But it's
also a gain to clarity if callers don't have to pass in dummy, unused,
result arguments.
Regards,
/Niels
--
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
More information about the gmp-devel
mailing list