[Gmp-commit] /var/hg/gmp-5.0: Backport bugfixes to mpz functions.

mercurial at gmplib.org mercurial at gmplib.org
Thu May 24 14:26:32 CEST 2012


details:   /var/hg/gmp-5.0/rev/5e296f996b87
changeset: 13581:5e296f996b87
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu May 24 14:26:27 2012 +0200
description:
Backport bugfixes to mpz functions.

diffstat:

 ChangeLog            |  14 ++++++++++++++
 mpz/n_pow_ui.c       |   2 +-
 mpz/remove.c         |   2 +-
 mpz/rootrem.c        |   2 +-
 tests/mpz/t-remove.c |   2 ++
 tests/mpz/t-root.c   |  11 +++++++++--
 6 files changed, 28 insertions(+), 5 deletions(-)

diffs (103 lines):

diff -r e696ba32ac81 -r 5e296f996b87 ChangeLog
--- a/ChangeLog	Sun May 06 13:19:36 2012 +0200
+++ b/ChangeLog	Thu May 24 14:26:27 2012 +0200
@@ -1,3 +1,17 @@
+2012-05-24  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpz/n_pow_ui.c: Cast non-limb count_leading_zeros argument.
+
+2012-05-24 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/remove.c: Support negative divisor.
+	* tests/mpz/t-remove.c: Test negative divisor.
+
+2012-05-17 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/rootrem.c: Correctly handle odd roots of negatives.
+	* tests/mpz/t-root.c: Test it.
+
 2012-05-06  Torbjorn Granlund  <tege at gmplib.org>
 
 	* Version 5.0.5 released.
diff -r e696ba32ac81 -r 5e296f996b87 mpz/n_pow_ui.c
--- a/mpz/n_pow_ui.c	Sun May 06 13:19:36 2012 +0200
+++ b/mpz/n_pow_ui.c	Thu May 24 14:26:27 2012 +0200
@@ -406,7 +406,7 @@
 
       /* Go from high to low over the bits of e, starting with i pointing at
          the bit below the highest 1 (which will mean i==-1 if e==1).  */
-      count_leading_zeros (cnt, e);
+      count_leading_zeros (cnt, (mp_limb_t) e);
       i = GMP_LIMB_BITS - cnt - 2;
 
 #if HAVE_NATIVE_mpn_mul_2
diff -r e696ba32ac81 -r 5e296f996b87 mpz/remove.c
--- a/mpz/remove.c	Sun May 06 13:19:36 2012 +0200
+++ b/mpz/remove.c	Thu May 24 14:26:27 2012 +0200
@@ -28,7 +28,7 @@
   mp_bitcnt_t pwr;
   int p;
 
-  if (mpz_cmp_ui (f, 1) <= 0)
+  if (mpz_cmpabs_ui (f, 1) <= 0)
     DIVIDE_BY_ZERO;
 
   if (SIZ (src) == 0)
diff -r e696ba32ac81 -r 5e296f996b87 mpz/rootrem.c
--- a/mpz/rootrem.c	Sun May 06 13:19:36 2012 +0200
+++ b/mpz/rootrem.c	Thu May 24 14:26:27 2012 +0200
@@ -85,6 +85,6 @@
 	MPN_COPY (up, remp, remn);
     }
 
-  SIZ(rem) = remn;
+  SIZ(rem) = us >= 0 ? remn : -remn;
   TMP_FREE;
 }
diff -r e696ba32ac81 -r 5e296f996b87 tests/mpz/t-remove.c
--- a/tests/mpz/t-remove.c	Sun May 06 13:19:36 2012 +0200
+++ b/tests/mpz/t-remove.c	Thu May 24 14:26:27 2012 +0200
@@ -73,6 +73,8 @@
 
       mpz_urandomb (bs, rands, 32);
       exp = mpz_get_ui (bs) % (5 + 10000 / mpz_sizeinbase (divisor, 2));
+      if (mpz_get_ui (bs) & 2)
+	mpz_neg (divisor, divisor);
       mpz_pow_ui (t, divisor, exp);
       mpz_mul (dividend, dividend, t);
 
diff -r e696ba32ac81 -r 5e296f996b87 tests/mpz/t-root.c
--- a/tests/mpz/t-root.c	Sun May 06 13:19:36 2012 +0200
+++ b/tests/mpz/t-root.c	Thu May 24 14:26:27 2012 +0200
@@ -49,7 +49,7 @@
   mpz_add (temp2, temp, rem2);
 
   /* Is power of result > argument?  */
-  if (mpz_cmp (root1, root2) != 0 || mpz_cmp (x2, temp2) != 0 || mpz_cmp (temp, x2) > 0)
+  if (mpz_cmp (root1, root2) != 0 || mpz_cmp (x2, temp2) != 0 || mpz_cmpabs (temp, x2) > 0)
     {
       fprintf (stderr, "ERROR after test %d\n", i);
       debug_mp (x2, 10);
@@ -68,7 +68,7 @@
       abort ();
     }
 
-  if (nth <= 10000)		/* skip too expensive test */
+  if (nth <= 10000 && mpz_sgn(x2) > 0)		/* skip too expensive test */
     {
       mpz_add_ui (temp2, root1, 1L);
       mpz_pow_ui (temp2, temp2, nth);
@@ -150,6 +150,13 @@
 	}
 
       check_one (root1, x2, nth, i);
+
+      if (((nth & 1) != 0) && ((bsi & 2) != 0))
+	{
+	  mpz_neg (x2, x2);
+	  mpz_neg (root1, root1);
+	  check_one (root1, x2, nth, i);
+	}
     }
 
   mpz_clear (bs);


More information about the gmp-commit mailing list