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

mercurial at gmplib.org mercurial at gmplib.org
Thu Apr 19 21:59:46 CEST 2012


details:   /var/hg/gmp/rev/cf632ee0b72d
changeset: 14857:cf632ee0b72d
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Thu Apr 19 21:51:55 2012 +0200
description:
Use CNST_LIMB.

details:   /var/hg/gmp/rev/75b1d81619f1
changeset: 14858:75b1d81619f1
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Thu Apr 19 21:53:20 2012 +0200
description:
Remove dead code.  Use CNST_LIMB.

details:   /var/hg/gmp/rev/78d8535c9d37
changeset: 14859:78d8535c9d37
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Thu Apr 19 21:55:35 2012 +0200
description:
Test mpz_mod.

details:   /var/hg/gmp/rev/b3599e7a66c2
changeset: 14860:b3599e7a66c2
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Thu Apr 19 21:56:31 2012 +0200
description:
Test divisibility by zero.

details:   /var/hg/gmp/rev/cf8e33d6e17e
changeset: 14861:cf8e33d6e17e
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Thu Apr 19 21:58:59 2012 +0200
description:
Generalisations for better test coverage.

diffstat:

 mpz/clrbit.c        |  11 ++++++-----
 mpz/setbit.c        |  28 ++++++----------------------
 tests/mpz/reuse.c   |   6 +++---
 tests/mpz/t-cong.c  |  11 ++++++++---
 tests/mpz/t-divis.c |   2 ++
 5 files changed, 25 insertions(+), 33 deletions(-)

diffs (177 lines):

diff -r 692bc6eee88d -r cf8e33d6e17e mpz/clrbit.c
--- a/mpz/clrbit.c	Thu Apr 19 11:29:36 2012 +0200
+++ b/mpz/clrbit.c	Thu Apr 19 21:58:59 2012 +0200
@@ -1,6 +1,7 @@
 /* mpz_clrbit -- clear a specified bit.
 
-Copyright 1991, 1993, 1994, 1995, 2001, 2002 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1995, 2001, 2002, 2012 Free Software Foundation,
+Inc.
 
 This file is part of the GNU MP Library.
 
@@ -34,7 +35,7 @@
 	{
 	  mp_limb_t  dlimb;
 	  dlimb = dp[limb_index];
-	  dlimb &= ~((mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS));
+	  dlimb &= ~(CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS));
 	  dp[limb_index] = dlimb;
 
 	  if (UNLIKELY (dlimb == 0 && limb_index == dsize-1))
@@ -69,7 +70,7 @@
       if (limb_index > zero_bound)
 	{
 	  if (limb_index < dsize)
-	    dp[limb_index] |= (mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS);
+	    dp[limb_index] |= CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS);
 	  else
 	    {
 	      /* Ugh.  The bit should be cleared outside of the end of the
@@ -77,14 +78,14 @@
 	      dp = MPZ_REALLOC (d, limb_index + 1);
 
 	      MPN_ZERO (dp + dsize, limb_index - dsize);
-	      dp[limb_index] = (mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS);
+	      dp[limb_index] = CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS);
 	      SIZ (d) = -(limb_index + 1);
 	    }
 	}
       else if (limb_index == zero_bound)
 	{
 	  dp[limb_index] = ((((dp[limb_index] - 1)
-			      | ((mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS))) + 1)
+			      | (CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS))) + 1)
 			    & GMP_NUMB_MASK);
 	  if (dp[limb_index] == 0)
 	    {
diff -r 692bc6eee88d -r cf8e33d6e17e mpz/setbit.c
--- a/mpz/setbit.c	Thu Apr 19 11:29:36 2012 +0200
+++ b/mpz/setbit.c	Thu Apr 19 21:58:59 2012 +0200
@@ -33,7 +33,7 @@
     {
       if (limb_index < dsize)
 	{
-	  dp[limb_index] |= (mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS);
+	  dp[limb_index] |= CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS);
 	  SIZ (d) = dsize;
 	}
       else
@@ -42,7 +42,7 @@
 	     number.  We have to increase the size of the number.  */
 	  dp = MPZ_REALLOC (d, limb_index + 1);
 	  MPN_ZERO (dp + dsize, limb_index - dsize);
-	  dp[limb_index] = (mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS);
+	  dp[limb_index] = CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS);
 	  SIZ (d) = limb_index + 1;
 	}
     }
@@ -69,7 +69,7 @@
 	    {
 	      mp_limb_t	 dlimb;
 	      dlimb = dp[limb_index];
-	      dlimb &= ~((mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS));
+	      dlimb &= ~(CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS));
 	      dp[limb_index] = dlimb;
 
 	      if (UNLIKELY (dlimb == 0 && limb_index == dsize-1))
@@ -85,29 +85,13 @@
       else if (limb_index == zero_bound)
 	{
 	  dp[limb_index] = ((dp[limb_index] - 1)
-			    & ~((mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS))) + 1;
-	  if (dp[limb_index] == 0)
-	    {
-	      mp_size_t i;
-	      for (i = limb_index + 1; i < dsize; i++)
-		{
-		  dp[i] += 1;
-		  if (dp[i] != 0)
-		    goto fin;
-		}
-	      /* We got carry all way out beyond the end of D.  Increase
-		 its size (and allocation if necessary).  */
-	      dsize++;
-	      dp = MPZ_REALLOC (d, dsize);
-	      dp[i] = 1;
-	      SIZ (d) = -dsize;
-	    fin:;
-	    }
+			    & ~(CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS))) + 1;
+	  ASSERT (dp[limb_index] != 0);
 	}
       else
 	{
 	  mpn_decr_u (dp + limb_index,
-		     (mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS));
+		     CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS));
 	  dsize -= dp[dsize - 1] == 0;
 	  SIZ (d) = -dsize;
 	}
diff -r 692bc6eee88d -r cf8e33d6e17e tests/mpz/reuse.c
--- a/tests/mpz/reuse.c	Thu Apr 19 11:29:36 2012 +0200
+++ b/tests/mpz/reuse.c	Thu Apr 19 21:58:59 2012 +0200
@@ -70,18 +70,18 @@
 dss_func dss_funcs[] =
 {
   mpz_add, mpz_sub, mpz_mul,
-  mpz_cdiv_q, mpz_cdiv_r, mpz_fdiv_q, mpz_fdiv_r, mpz_tdiv_q, mpz_tdiv_r,
+  mpz_cdiv_q, mpz_cdiv_r, mpz_fdiv_q, mpz_fdiv_r, mpz_tdiv_q, mpz_tdiv_r, mpz_mod,
   mpz_xinvert,
   mpz_gcd, mpz_lcm, mpz_and, mpz_ior, mpz_xor
 };
 const char *dss_func_names[] =
 {
   "mpz_add", "mpz_sub", "mpz_mul",
-  "mpz_cdiv_q", "mpz_cdiv_r", "mpz_fdiv_q", "mpz_fdiv_r", "mpz_tdiv_q", "mpz_tdiv_r",
+  "mpz_cdiv_q", "mpz_cdiv_r", "mpz_fdiv_q", "mpz_fdiv_r", "mpz_tdiv_q", "mpz_tdiv_r", "mpz_mod",
   "mpz_xinvert",
   "mpz_gcd", "mpz_lcm", "mpz_and", "mpz_ior", "mpz_xor"
 };
-char dss_func_division[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
+char dss_func_division[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
 
 dsi_func dsi_funcs[] =
 {
diff -r 692bc6eee88d -r cf8e33d6e17e tests/mpz/t-cong.c
--- a/tests/mpz/t-cong.c	Thu Apr 19 11:29:36 2012 +0200
+++ b/tests/mpz/t-cong.c	Thu Apr 19 21:58:59 2012 +0200
@@ -83,6 +83,11 @@
 
   } data[] = {
 
+    /* strict equality mod 0 */
+    { "0", "0", "0", 1 },
+    { "11", "11", "0", 1 },
+    { "3", "11", "0", 0 },
+
     /* anything congruent mod 1 */
     { "0", "0", "1", 1 },
     { "1", "0", "1", 1 },
@@ -146,11 +151,11 @@
 
   for (i = 0; i < reps; i++)
     {
-      mpz_errandomb (a, rands, 8*GMP_LIMB_BITS);
+      mpz_errandomb (a, rands, 100*GMP_LIMB_BITS);
       MPZ_CHECK_FORMAT (a);
-      mpz_errandomb (c, rands, 8*GMP_LIMB_BITS);
+      mpz_errandomb (c, rands, 100*GMP_LIMB_BITS);
       MPZ_CHECK_FORMAT (c);
-      mpz_errandomb_nonzero (d, rands, 8*GMP_LIMB_BITS);
+      mpz_errandomb_nonzero (d, rands, 100*GMP_LIMB_BITS);
 
       mpz_negrandom (a, rands);
       MPZ_CHECK_FORMAT (a);
diff -r 692bc6eee88d -r cf8e33d6e17e tests/mpz/t-divis.c
--- a/tests/mpz/t-divis.c	Thu Apr 19 11:29:36 2012 +0200
+++ b/tests/mpz/t-divis.c	Thu Apr 19 21:58:59 2012 +0200
@@ -71,6 +71,8 @@
 
   } data[] = {
 
+    { "0",    "0", 1 },
+    { "17",   "0", 0 },
     { "0",    "1", 1 },
     { "123",  "1", 1 },
     { "-123", "1", 1 },


More information about the gmp-commit mailing list