New or modified function
Niels Möller
nisse at lysator.liu.se
Fri Nov 20 14:50:05 CET 2009
Wojciech Florek <Wojciech.Florek at amu.edu.pl> writes:
> modify mpz_lcm in
> such way, that it will return also gcd
> mpz_newlcm(mpz_ptr g, mpz_ptr l, mpz_srcptr a, mpz_srcptr b)
> (g may be NULL). In this way I don't need to invoke mpz_gcd myself.
I was thinking of something like this (totally untested):
void exmul (mpz_t r, mpz_t a, mpz_t b)
{
mpz_t g;
mpz_t t;
mpz_init(t);
mpz_init(g);
mpz_gcd (g, a, b);
mpz_divexact (t, a, g);
mpz_divexact (g, b, g);
mpz_mul (r, t, g);
mpz_clear(t);
mpz_clear(g);
}
Any reason why this isn't good enough? Not sure if you want it to
return the gcd as well, but if that's what you need, that's easy to
arrange.
> However, I still thing that the function, I've called "exclusive
> multiplication", can be interested from the point of view of the
> number theory (I've used it in some other places, too). Therefore, its
> inclusion in the further versions of the (fantastic!) GNU MP Library
> seems to be well motivated.
Any other examples where it's needed? If it's easier to rewrite the
function than to read the corresponding documentation (if it were to
be included in GMP), I think it ought to be quite widely useful before
it makes sense to include it in the library (this is my persoonal
opinion, I'm not going to be the one deciding on this).
Regards,
/Niels
More information about the gmp-discuss
mailing list