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

mercurial at gmplib.org mercurial at gmplib.org
Sun Apr 17 10:54:21 CEST 2022


details:   /var/hg/gmp/rev/1bd5019ce5b5
changeset: 18344:1bd5019ce5b5
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Apr 17 09:24:15 2022 +0200
description:
mini-gmp/mini-mpq.c (mpq_helper_canonicalize): Init only if needed

details:   /var/hg/gmp/rev/55b05c568ce9
changeset: 18345:55b05c568ce9
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Apr 17 09:32:29 2022 +0200
description:
ChangeLog

diffstat:

 mini-gmp/ChangeLog  |   3 +++
 mini-gmp/mini-mpq.c |  22 +++++++++-------------
 2 files changed, 12 insertions(+), 13 deletions(-)

diffs (71 lines):

diff -r 05438c96d518 -r 55b05c568ce9 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Sat Apr 09 07:54:54 2022 +0200
+++ b/mini-gmp/ChangeLog	Sun Apr 17 09:32:29 2022 +0200
@@ -1,3 +1,6 @@
+2022-04-17 Marco Bodrato <bodrato at mail.dm.unipi.it>
+	* mini-mpq.c (mpq_helper_canonicalize): Remove tmp parameter.
+
 2022-03-19 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mini-gmp.c (mpz_swap): Use MPN_PTR_SWAP, tx Paul Eggert.
diff -r 05438c96d518 -r 55b05c568ce9 mini-gmp/mini-mpq.c
--- a/mini-gmp/mini-mpq.c	Sat Apr 09 07:54:54 2022 +0200
+++ b/mini-gmp/mini-mpq.c	Sun Apr 17 09:32:29 2022 +0200
@@ -119,15 +119,19 @@
 }
 
 static void
-mpq_helper_canonicalize (mpq_t r, const mpz_t num, const mpz_t den, mpz_t g)
+mpq_helper_canonicalize (mpq_t r, const mpz_t num, const mpz_t den)
 {
   if (num->_mp_size == 0)
     mpq_set_ui (r, 0, 1);
   else
     {
+      mpz_t g;
+
+      mpz_init (g);
       mpz_gcd (g, num, den);
       mpz_tdiv_q (mpq_numref (r), num, g);
       mpz_tdiv_q (mpq_denref (r), den, g);
+      mpz_clear (g);
       mpq_canonical_sign (r);
     }
 }
@@ -135,11 +139,7 @@
 void
 mpq_canonicalize (mpq_t r)
 {
-  mpz_t t;
-
-  mpz_init (t);
-  mpq_helper_canonicalize (r, mpq_numref (r), mpq_denref (r), t);
-  mpz_clear (t);
+  mpq_helper_canonicalize (r, mpq_numref (r), mpq_denref (r));
 }
 
 void
@@ -260,7 +260,7 @@
   } else {
     int ret;
 
-    mpq_init (t);
+    mpq_nan_init (t);
     mpq_set_ui (t, n, d);
     ret = mpq_cmp (q, t);
     mpq_clear (t);
@@ -378,12 +378,8 @@
   mpq_nan_init (t);
 
   if (a != b) {
-    mpz_t g;
-
-    mpz_init (g);
-    mpq_helper_canonicalize (t, mpq_numref (a), mpq_denref (b), g);
-    mpq_helper_canonicalize (r, mpq_numref (b), mpq_denref (a), g);
-    mpz_clear (g);
+    mpq_helper_canonicalize (t, mpq_numref (a), mpq_denref (b));
+    mpq_helper_canonicalize (r, mpq_numref (b), mpq_denref (a));
 
     a = r;
     b = t;


More information about the gmp-commit mailing list