[Gmp-commit] /var/hg/gmp: 3 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Wed Feb 28 07:24:23 UTC 2018


details:   /var/hg/gmp/rev/712b77b19752
changeset: 17575:712b77b19752
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Feb 28 08:18:49 2018 +0100
description:
gmpxx.h (__gmp_binary_{min,pl}us): Special case for mpq -/+ 1.

details:   /var/hg/gmp/rev/a22c11d52f05
changeset: 17576:a22c11d52f05
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Feb 28 08:22:48 2018 +0100
description:
gmpxx.h (__gmp_binary_equal): Optimised comparison mpq == integer.

details:   /var/hg/gmp/rev/45d04f4f51f4
changeset: 17577:45d04f4f51f4
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Feb 28 08:24:04 2018 +0100
description:
Changelog

diffstat:

 ChangeLog |   6 ++++++
 gmpxx.h   |  16 +++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diffs (63 lines):

diff -r dbd767bb43bf -r 45d04f4f51f4 ChangeLog
--- a/ChangeLog	Mon Feb 26 08:34:53 2018 +0100
+++ b/ChangeLog	Wed Feb 28 08:24:04 2018 +0100
@@ -1,3 +1,9 @@
+2018-02-28 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* gmpxx.h (__gmp_binary_plus): Special case for mpq + 1.
+	(__gmp_binary_minus): Special case for mpq - 1.
+	(__gmp_binary_equal): Optimised comparison mpq == integer.
+
 2018-02-18 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* tune/Makefile.am: Disallow parallel make (thanks Vincent Lefevre).
diff -r dbd767bb43bf -r 45d04f4f51f4 gmpxx.h
--- a/gmpxx.h	Mon Feb 26 08:34:53 2018 +0100
+++ b/gmpxx.h	Wed Feb 28 08:24:04 2018 +0100
@@ -220,6 +220,11 @@
     {
       if (q != r) mpq_set(q, r);
     }
+    else if (__GMPXX_CONSTANT(l) && l == 1)
+    {
+      mpz_add (mpq_numref(q), mpq_numref(r), mpq_denref(r));
+      if (q != r) mpz_set(mpq_denref(q), mpq_denref(r));
+    }
     else
     {
       if (q == r)
@@ -339,6 +344,11 @@
     {
       if (q != r) mpq_set(q, r);
     }
+    else if (__GMPXX_CONSTANT(l) && l == 1)
+    {
+      mpz_sub (mpq_numref(q), mpq_numref(r), mpq_denref(r));
+      if (q != r) mpz_set(mpq_denref(q), mpq_denref(r));
+    }
     else
     {
       if (q == r)
@@ -971,11 +981,11 @@
   { return mpq_equal(q, r) != 0; }
 
   static bool eval(mpq_srcptr q, unsigned long int l)
-  { return mpq_cmp_ui(q, l, 1) == 0; }
+  { return mpz_cmp_ui(mpq_denref(q), 1) == 0 && mpz_cmp_ui(mpq_numref(q), l) == 0; }
   static bool eval(unsigned long int l, mpq_srcptr q)
   { return eval(q, l); }
   static bool eval(mpq_srcptr q, signed long int l)
-  { return mpq_cmp_si(q, l, 1) == 0; }
+  { return mpz_cmp_ui(mpq_denref(q), 1) == 0 && mpz_cmp_si(mpq_numref(q), l) == 0; }
   static bool eval(signed long int l, mpq_srcptr q)
   { return eval(q, l); }
   static bool eval(mpq_srcptr q, double d)
@@ -983,7 +993,7 @@
   static bool eval(double d, mpq_srcptr q)
   { return eval(q, d); }
   static bool eval(mpq_srcptr q, mpz_srcptr z)
-  { return mpq_cmp_z(q, z) == 0; }
+  { return mpz_cmp_ui(mpq_denref(q), 1) == 0 && mpz_cmp(mpq_numref(q), z) == 0; }
   static bool eval(mpz_srcptr z, mpq_srcptr q)
   { return eval(q, z); }
 


More information about the gmp-commit mailing list