[Gmp-commit] /var/hg/gmp: tests/mpz/bit.c (check_clr_extend): Check _set shrink.

mercurial at gmplib.org mercurial at gmplib.org
Sun Dec 30 09:06:28 CET 2012


details:   /var/hg/gmp/rev/6c283c477e58
changeset: 15221:6c283c477e58
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Dec 30 09:06:09 2012 +0100
description:
tests/mpz/bit.c (check_clr_extend): Check _set shrink.

diffstat:

 ChangeLog       |   4 ++++
 tests/mpz/bit.c |  27 +++++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)

diffs (68 lines):

diff -r 986d7f6dab98 -r 6c283c477e58 ChangeLog
--- a/ChangeLog	Sat Dec 29 13:26:56 2012 +0100
+++ b/ChangeLog	Sun Dec 30 09:06:09 2012 +0100
@@ -1,3 +1,7 @@
+2012-12-30 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* tests/mpz/bit.c (check_clr_extend): Check _set shrink.
+
 2012-12-29  Torbjorn Granlund  <tege at gmplib.org>
 
 	* demos/calc/calc.c: Remove generated file from repo.
diff -r 986d7f6dab98 -r 6c283c477e58 tests/mpz/bit.c
--- a/tests/mpz/bit.c	Sat Dec 29 13:26:56 2012 +0100
+++ b/tests/mpz/bit.c	Sun Dec 30 09:06:09 2012 +0100
@@ -1,6 +1,6 @@
 /* Test mpz_setbit, mpz_clrbit, mpz_tstbit.
 
-Copyright 1997, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1997, 2000, 2001, 2002, 2003, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
@@ -38,6 +38,7 @@
 
 /* exercise the case where mpz_clrbit or mpz_combit ends up extending a
    value like -2^(k*GMP_NUMB_BITS-1) when clearing bit k*GMP_NUMB_BITS-1.  */
+/* And vice-versa. */
 void
 check_clr_extend (void)
 {
@@ -53,7 +54,7 @@
       for (f = 0; f <= 1; f++)
 	{
 	  /* lots of 1 bits in _mp_d */
-	  mpz_set_ui (got, 1L);
+	  mpz_set_si (got, 1L);
 	  mpz_mul_2exp (got, got, 10*GMP_NUMB_BITS);
 	  mpz_sub_ui (got, got, 1L);
 
@@ -82,6 +83,28 @@
 	      mpz_trace ("want", want);
 	      abort ();
 	    }
+
+	  /* complement bit n, going back to ..11100..00 which is -2^(n-1) */
+	  if (f == 0)
+	    mpz_setbit (got, i*GMP_NUMB_BITS-1);
+	  else
+	    mpz_combit (got, i*GMP_NUMB_BITS-1);
+	  MPZ_CHECK_FORMAT (got);
+
+	  mpz_set_si (want, -1L);
+	  mpz_mul_2exp (want, want, i*GMP_NUMB_BITS - 1);
+
+	  if (mpz_cmp (got, want) != 0)
+	    {
+	      if (f == 0)
+		printf ("mpz_setbit: ");
+	      else
+		printf ("mpz_combit: ");
+	      printf ("wrong after shrinking\n");
+	      mpz_trace ("got ", got);
+	      mpz_trace ("want", want);
+	      abort ();
+	    }
 	}
     }
 


More information about the gmp-commit mailing list