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

mercurial at gmplib.org mercurial at gmplib.org
Fri Jan 11 10:37:42 CET 2013


details:   /var/hg/gmp/rev/aaf481421d77
changeset: 15258:aaf481421d77
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jan 11 10:27:53 2013 +0100
description:
Reverted non-bugfix improvements to mini-gmp, keep them for the next release.

details:   /var/hg/gmp/rev/5fcc2ca00c74
changeset: 15259:5fcc2ca00c74
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jan 11 10:37:20 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_mul_si): Simplify.

diffstat:

 ChangeLog           |   4 +-
 mini-gmp/mini-gmp.c |  54 +++++++++++++++++++---------------------------------
 2 files changed, 22 insertions(+), 36 deletions(-)

diffs (95 lines):

diff -r 5726b8afa3b0 -r 5fcc2ca00c74 ChangeLog
--- a/ChangeLog	Fri Jan 11 09:16:39 2013 +0100
+++ b/ChangeLog	Fri Jan 11 10:37:20 2013 +0100
@@ -3,8 +3,8 @@
 	* mini-gmp/tests/t-comb.c: New test program, testing both
 	mpz_fac_ui and mpz_bin_uiui.
 	* mini-gmp/tests/Makefile (CHECK_PROGRAMS): Added t-comb.
-	* mini-gmp/mini-gmp.c (mpz_fac_ui): Remove a branch.
-	(mpz_bin_uiui): Rewrite.
+
+	* mini-gmp/mini-gmp.c (mpz_mul_si): Simplify.
 
 2013-01-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
diff -r 5726b8afa3b0 -r 5fcc2ca00c74 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Fri Jan 11 09:16:39 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Fri Jan 11 10:37:20 2013 +0100
@@ -1906,30 +1906,13 @@
 void
 mpz_mul_si (mpz_t r, const mpz_t u, long int v)
 {
-  int sign;
-  mp_size_t un;
-  mpz_t t;
-  mp_ptr tp;
-  mp_limb_t cy;
-
-  if (v == 0)
+  if (v < 0)
     {
-      r->_mp_size = 0;
-      return;
+      mpz_mul_ui (r, u, -((unsigned long int)(v + 1) - 1)); /* ABS_CAST */
+      mpz_neg (r, r);
     }
-  sign = (u->_mp_size ^ v) < 0;
-
-  un = GMP_ABS (u->_mp_size);
-  mpz_init (t);
-
-  tp = MPZ_REALLOC (t, un + 1);
-  cy = mpn_mul_1 (tp, u->_mp_d, un, GMP_ABS (v));
-  tp[un] = cy;
-  un += cy > 0;
-
-  t->_mp_size = sign ? - un : un;
-  mpz_swap (r, t);
-  mpz_clear (t);
+  else
+    mpz_mul_ui (r, u, (unsigned long int) v);
 }
 
 void
@@ -3184,26 +3167,29 @@
 void
 mpz_fac_ui (mpz_t x, unsigned long n)
 {
-  mpz_set_ui (x, n + (n == 0));
-  for (;n > 2;)
-    mpz_mul_ui (x, x, --n);
+  if (n < 2) {
+    mpz_set_ui (x, 1);
+    return;
+  }
+  mpz_set_ui (x, n);
+  for (;--n > 1;)
+    mpz_mul_ui (x, x, n);
 }
 
 void
 mpz_bin_uiui (mpz_t r, unsigned long n, unsigned long k)
 {
   mpz_t t;
-  mpz_set_ui (r, k <= n);
-
-  if (k > (n >> 1))
-    k = (k <= n) ? n - k : 0;
-
+
+  if (k > n) {
+    r->_mp_size = 0;
+    return;
+  }
+  mpz_fac_ui (r, n);
   mpz_init (t);
   mpz_fac_ui (t, k);
-
-  for (; k > 0; k--)
-      mpz_mul_ui (r, r, n--);
-
+  mpz_divexact (r, r, t);
+  mpz_fac_ui (t, n - k);
   mpz_divexact (r, r, t);
   mpz_clear (t);
 }


More information about the gmp-commit mailing list