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

mercurial at gmplib.org mercurial at gmplib.org
Tue Jan 15 22:22:04 CET 2013


details:   /var/hg/gmp/rev/aa9e8eec5929
changeset: 15277:aa9e8eec5929
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Jan 15 22:13:29 2013 +0100
description:
mini-gmp/tests/t-logops.c: Improve popcount/hamdist testing.

details:   /var/hg/gmp/rev/1cf2121062c3
changeset: 15278:1cf2121062c3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Jan 15 22:21:52 2013 +0100
description:
mini-gmp/tests/t-signed.c: Test more cases.

diffstat:

 ChangeLog                 |   5 +++++
 mini-gmp/tests/t-logops.c |  22 +++++++++++++++++-----
 mini-gmp/tests/t-signed.c |  36 +++++++++++++++++++++++++++---------
 3 files changed, 49 insertions(+), 14 deletions(-)

diffs (126 lines):

diff -r a24331c4ed27 -r 1cf2121062c3 ChangeLog
--- a/ChangeLog	Tue Jan 15 01:24:14 2013 +0100
+++ b/ChangeLog	Tue Jan 15 22:21:52 2013 +0100
@@ -1,3 +1,8 @@
+2013-01-15 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mini-gmp/tests/t-logops.c: Improve popcount/hamdist testing.
+	* mini-gmp/tests/t-signed.c: Test more cases.
+
 2013-01-15  Torbjorn Granlund  <tege at gmplib.org>
 
 	From Mike Frysinger:
diff -r a24331c4ed27 -r 1cf2121062c3 mini-gmp/tests/t-logops.c
--- a/mini-gmp/tests/t-logops.c	Tue Jan 15 01:24:14 2013 +0100
+++ b/mini-gmp/tests/t-logops.c	Tue Jan 15 22:21:52 2013 +0100
@@ -1,6 +1,6 @@
 /*
 
-Copyright 2012, Free Software Foundation, Inc.
+Copyright 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
@@ -39,6 +39,7 @@
 {
   unsigned i;
   mpz_t a, b, res, ref;
+  mp_bitcnt_t c;
 
   hex_random_init ();
 
@@ -85,14 +86,25 @@
 	  abort ();
 	}
 
-      if (mpz_popcount (a) != mpz_hamdist (res, b))
+      if (i % 8) {
+	c = 0;
+	mpz_mul_2exp (res, res, i % 8);
+      } else if (mpz_sgn (res) >= 0) {
+	c = mpz_odd_p (res) != 0;
+	mpz_tdiv_q_2exp (res, res, 1);
+      } else {
+	c = (~ (mp_bitcnt_t) 0) - 3;
+	mpz_set_ui (res, 11 << ((i >> 3)%4)); /* set 3 bits */
+      } 
+
+      if (mpz_popcount (res) + c != mpz_hamdist (a, b))
 	{
-	  fprintf (stderr, "mpz_popcount(a) and mpz_hamdist(r,b) differ:\n");
+	  fprintf (stderr, "mpz_popcount(r) + %lu and mpz_hamdist(a,b) differ:\n", c);
 	  dump ("a", a);
 	  dump ("b", b);
 	  dump ("r", res);
-	  fprintf (stderr, "mpz_popcount(a) = %lu:\n", mpz_popcount (a));
-	  fprintf (stderr, "mpz_hamdist(r,b) = %lu:\n", mpz_hamdist (res, b));
+	  fprintf (stderr, "mpz_popcount(r) = %lu:\n", mpz_popcount (res));
+	  fprintf (stderr, "mpz_hamdist(a,b) = %lu:\n", mpz_hamdist (a, b));
 	  abort ();
 	}
     }
diff -r a24331c4ed27 -r 1cf2121062c3 mini-gmp/tests/t-signed.c
--- a/mini-gmp/tests/t-signed.c	Tue Jan 15 01:24:14 2013 +0100
+++ b/mini-gmp/tests/t-signed.c	Tue Jan 15 22:21:52 2013 +0100
@@ -80,9 +80,30 @@
       }
 
     if ((si < oi ? -1 : si > oi) != c)
+      {
+	mpz_set (oz, sz);
+	break;
+      }
+
+    check_si (sz, oz, si, c);
+
+    oi = si + c;
+    if (c == -1)
+      mpz_sub_ui (oz, sz, 1);
+    else
+      mpz_add_ui (oz, sz, 1);
+
+    if (mpz_cmp_si (oz, si) != c)
+      {
+	printf ("mpz_cmp_si (oz, %ld) != %i.\n", si, c);
+	printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
+	abort ();
+      }
+
+    if ((oi < si ? -1 : oi > si) != c)
       break;
 
-    check_si (sz, oz, si, c);
+    check_si (oz, sz, oi, c);
 
     oi = (si - c) * 2 + c;
     mpz_mul_si (oz, sz, 2*c); 
@@ -99,24 +120,21 @@
       }
 
     if ((oi < si ? -1 : oi > si) != c)
-      {
-	mpz_set (sz, oz);
-	break;
-      }
+      break;
 
     check_si (oz, sz, oi, c);
   } while (1);
 
-  mpz_clear (oz);
+  mpz_clear (sz);
 
-  if (mpz_fits_slong_p (sz))
+  if (mpz_fits_slong_p (oz))
     {
       printf ("Should not fit a signed long any more.\n");
-      printf (" sz="); mpz_out_str (stdout, 10, sz); printf ("\n");
+      printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
       abort ();
     }
 
-  mpz_clear (sz);
+  mpz_clear (oz);
 }
 
 int


More information about the gmp-commit mailing list