mini-gmp and mpq

Marco Bodrato bodrato at mail.dm.unipi.it
Thu Mar 1 02:44:24 UTC 2018


Ciao,

Il Mer, 28 Febbraio 2018 9:20 pm, Marc Glisse ha scritto:
> On Wed, 28 Feb 2018, Marco Bodrato wrote:
>> In the meanwhile I also pushed some small shortcuts for
>> __gmp_binary_equal applied to mpq and integers:

> Thanks, that's a good idea. If we wanted to, we could also specialize the
> test q == 0 (and q < 0), which is probably common enough, but that's
> independent, and a negligible gain.

On the inequality side, q < 0 (and q < 1) should be correctly handled by
the code in gmp.h:

#define mpq_cmp_ui(Q,NUI,DUI)					\
  (__builtin_constant_p (NUI) && (NUI) == 0 ? mpq_sgn (Q)	\
   : __builtin_constant_p ((NUI) == (DUI)) && (NUI) == (DUI)	\
   ? mpz_cmp (mpq_numref (Q), mpq_denref (Q))			\
   : _mpq_cmp_ui (Q,NUI,DUI))

So, my last push was a regression for the special case you mention: q==0.
The following correction should heal it (and alike for _si):

-  { return mpz_cmp_ui(mpq_denref(q), 1) == 0 && mpz_cmp_ui(mpq_numref(q),
l) == 0; }
+  { return ((__GMPXX_CONSTANT(l) && l == 0) ||
+	    mpz_cmp_ui(mpq_denref(q), 1) == 0) &&
+      mpz_cmp_ui(mpq_numref(q), l) == 0; }

Ĝis,
m

-- 
http://bodrato.it/papers/



More information about the gmp-devel mailing list