mpq_cmp_z
Marco Bodrato
bodrato at mail.dm.unipi.it
Wed Aug 19 18:26:04 UTC 2015
Ciao,
On Sun, August 16, 2015 11:50 pm, Torbjörn Granlund wrote:
> On Sat, August 15, 2015 12:37 pm, Vincent Delecroix wrote:
> > rationals. We often have to compare integers with rationals and I came
> > to the conclusion that it would be convenient to have a GMP function
> >
> > int mpq_cmp_z(mpq_t, mpz_t)
> We might consider some code sharing between the mpq_cmp and this
> function, they look very similar.
I looked at "code sharing" in mpz/aors.h (a single file compiled with
different definitions to obtain two similar functions) and in mpq/aors.c
(two wrapper functions just setting a parameter for a single general
implementation), but I doubt either of the two models can be easily
applied to the mpq_cmp{,_q} case.
> We might even just put the mpz in stack allocated mpq structure and fall
> into mpq_cmp with a tail call.
Should we specialise code in mpq_cmp so that it is faster when a
denominator is 1? Then write:
mpq_cmp_z (mpq_srcptr q, mpz_srcptr z)
{
static const mp_limb_t dummy = 1;
mpq_t qz;
SIZ(NUM(qz)) = SIZ(z);
PTR(NUM(qz)) = PTR(z);
SIZ(DEN(qz)) = 1;
PTR(DEN(qz)) = &dummy;
return mpq_cmp (q, qz);
}
Do you mean something like that?
--
http://bodrato.it/
More information about the gmp-devel
mailing list