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

mercurial at gmplib.org mercurial at gmplib.org
Sat May 16 14:22:36 UTC 2020


details:   /var/hg/gmp-6.2/rev/12dc28ec908d
changeset: 18024:12dc28ec908d
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sat May 16 16:18:55 2020 +0200
description:
Avoid C99 constructs.

details:   /var/hg/gmp-6.2/rev/4f49043597df
changeset: 18025:4f49043597df
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sat May 16 16:21:33 2020 +0200
description:
Rename tests/mpz/bit.c to avoid clash with new C++ include file.

diffstat:

 mpn/generic/gcd_22.c  |    2 +-
 tests/mpz/Makefile.am |    2 +-
 tests/mpz/bit.c       |  405 --------------------------------------------------
 tests/mpz/t-bit.c     |  405 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 407 insertions(+), 407 deletions(-)

diffs (truncated from 848 to 300 lines):

diff -r 0fcaadf6e489 -r 4f49043597df mpn/generic/gcd_22.c
--- a/mpn/generic/gcd_22.c	Tue May 12 22:51:55 2020 +0200
+++ b/mpn/generic/gcd_22.c	Sat May 16 16:21:33 2020 +0200
@@ -56,13 +56,13 @@
 
       if (UNLIKELY (t0 == 0))
 	{
+	  int c;
 	  if (t1 == 0)
 	    {
 	      g.d1 = (u1 << 1) | (u0 >> (GMP_LIMB_BITS - 1));
 	      g.d0 = (u0 << 1) | 1;
 	      return g;
 	    }
-	  int c;
 	  count_trailing_zeros (c, t1);
 
 	  /* v1 = min (u1, v1) */
diff -r 0fcaadf6e489 -r 4f49043597df tests/mpz/Makefile.am
--- a/tests/mpz/Makefile.am	Tue May 12 22:51:55 2020 +0200
+++ b/tests/mpz/Makefile.am	Sat May 16 16:21:33 2020 +0200
@@ -24,7 +24,7 @@
 
 check_PROGRAMS = reuse t-addsub t-cmp t-mul t-mul_i t-tdiv t-tdiv_ui t-fdiv \
   t-fdiv_ui t-cdiv_ui t-gcd t-gcd_ui t-lcm t-invert dive dive_ui t-sqrtrem \
-  convert io t-inp_str logic bit t-powm t-powm_ui t-pow t-div_2exp      \
+  convert io t-inp_str logic t-bit t-powm t-powm_ui t-pow t-div_2exp      \
   t-root t-perfsqr t-perfpow t-jac t-bin t-get_d t-get_d_2exp t-get_si	\
   t-set_d t-set_si t-lucm						\
   t-fac_ui t-mfac_uiui t-primorial_ui t-fib_ui t-lucnum_ui t-scan t-fits   \
diff -r 0fcaadf6e489 -r 4f49043597df tests/mpz/bit.c
--- a/tests/mpz/bit.c	Tue May 12 22:51:55 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,405 +0,0 @@
-/* Test mpz_setbit, mpz_clrbit, mpz_tstbit.
-
-Copyright 1997, 2000-2003, 2012, 2013 Free Software Foundation, Inc.
-
-This file is part of the GNU MP Library test suite.
-
-The GNU MP Library test suite is free software; you can redistribute it
-and/or modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 3 of the License,
-or (at your option) any later version.
-
-The GNU MP Library test suite is distributed in the hope that it will be
-useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
-Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "gmp-impl.h"
-#include "tests.h"
-
-#ifndef SIZE
-#define SIZE 4
-#endif
-
-
-void
-debug_mp (mpz_srcptr x, int base)
-{
-  mpz_out_str (stdout, base, x); fputc ('\n', stdout);
-}
-
-
-/* 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)
-{
-  mpz_t          got, want;
-  unsigned long  i;
-  int            f;
-
-  mpz_init (got);
-  mpz_init (want);
-
-  for (i = 1; i < 5; i++)
-    {
-      for (f = 0; f <= 1; f++)
-	{
-	  /* lots of 1 bits in _mp_d */
-	  mpz_set_si (got, 1L);
-	  mpz_mul_2exp (got, got, 10*GMP_NUMB_BITS);
-	  mpz_sub_ui (got, got, 1L);
-
-	  /* value -2^(n-1) representing ..11100..00 */
-	  mpz_set_si (got, -1L);
-	  mpz_mul_2exp (got, got, i*GMP_NUMB_BITS-1);
-
-	  /* complement bit n, giving ..11000..00 which is -2^n */
-	  if (f == 0)
-	    mpz_clrbit (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);
-
-	  if (mpz_cmp (got, want) != 0)
-	    {
-	      if (f == 0)
-		printf ("mpz_clrbit: ");
-	      else
-		printf ("mpz_combit: ");
-	      printf ("wrong after extension\n");
-	      mpz_trace ("got ", got);
-	      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 ();
-	    }
-	}
-    }
-
-  mpz_clear (got);
-  mpz_clear (want);
-}
-
-void
-check_com_negs (void)
-{
-  static const struct {
-    unsigned long  bit;
-    mp_size_t      inp_size;
-    mp_limb_t      inp_n[5];
-    mp_size_t      want_size;
-    mp_limb_t      want_n[5];
-  } data[] = {
-    { GMP_NUMB_BITS,   2, { 1, 1 },  1, { 1 } },
-    { GMP_NUMB_BITS+1, 2, { 1, 1 },  2, { 1, 3 } },
-
-    { GMP_NUMB_BITS,   2, { 0, 1 },  2, { 0, 2 } },
-    { GMP_NUMB_BITS+1, 2, { 0, 1 },  2, { 0, 3 } },
-  };
-  mpz_t  inp, got, want;
-  int    i;
-
-  mpz_init (got);
-  mpz_init (want);
-  mpz_init (inp);
-
-  for (i = 0; i < numberof (data); i++)
-    {
-      mpz_set_n (inp, data[i].inp_n, data[i].inp_size);
-      mpz_neg (inp, inp);
-
-      mpz_set_n (want, data[i].want_n, data[i].want_size);
-      mpz_neg (want, want);
-
-      mpz_set (got, inp);
-      mpz_combit (got, data[i].bit);
-
-      if (mpz_cmp (got, want) != 0)
-	{
-	  printf ("mpz_combit: wrong on neg data[%d]\n", i);
-	  mpz_trace ("inp ", inp);
-	  printf    ("bit %lu\n", data[i].bit);
-	  mpz_trace ("got ", got);
-	  mpz_trace ("want", want);
-	  abort ();
-	}
-    }
-
-  mpz_clear (inp);
-  mpz_clear (got);
-  mpz_clear (want);
-}
-
-/* See that mpz_tstbit matches a twos complement calculated explicitly, for
-   various low zeros.  */
-void
-check_tstbit (void)
-{
-#define MAX_ZEROS  3
-#define NUM_LIMBS  3
-
-  mp_limb_t      pos[1+NUM_LIMBS+MAX_ZEROS];
-  mp_limb_t      neg[1+NUM_LIMBS+MAX_ZEROS];
-  mpz_t          z;
-  unsigned long  i;
-  int            zeros, low1;
-  int            got, want;
-
-  mpz_init (z);
-  for (zeros = 0; zeros <= MAX_ZEROS; zeros++)
-    {
-      MPN_ZERO (pos, numberof(pos));
-      mpn_random2 (pos+zeros, (mp_size_t) NUM_LIMBS);
-
-      for (low1 = 0; low1 <= 1; low1++)
-	{
-	  if (low1)
-	    pos[0] |= 1;
-
-	  refmpn_neg (neg, pos, (mp_size_t) numberof(neg));
-	  mpz_set_n (z, neg, (mp_size_t) numberof(neg));
-	  mpz_neg (z, z);
-
-	  for (i = 0; i < numberof(pos)*GMP_NUMB_BITS; i++)
-	    {
-	      got = mpz_tstbit (z, i);
-	      want = refmpn_tstbit (pos, i);
-	      if (got != want)
-		{
-		  printf ("wrong at bit %lu, with %d zeros\n", i, zeros);
-		  printf ("z neg "); debug_mp (z, -16);
-		  mpz_set_n (z, pos, (mp_size_t) numberof(pos));
-		  printf ("pos   "); debug_mp (z, -16);
-		  mpz_set_n (z, neg, (mp_size_t) numberof(neg));
-		  printf ("neg   "); debug_mp (z, -16);
-		  exit (1);
-		}
-	    }
-	}
-    }
-  mpz_clear (z);
-}
-
-
-void
-check_single (void)
-{
-  mpz_t  x;
-  int    limb, offset, initial;
-  unsigned long  bit;
-
-  mpz_init (x);
-
-  for (limb = 0; limb < 4; limb++)
-    {
-      for (offset = (limb==0 ? 0 : -2); offset <= 2; offset++)
-	{
-	  for (initial = 1; initial >= -1; initial--)
-	    {
-	      mpz_set_si (x, (long) initial);
-
-	      bit = (unsigned long) limb*GMP_LIMB_BITS + offset;
-
-	      mpz_clrbit (x, bit);
-	      MPZ_CHECK_FORMAT (x);
-	      if (mpz_tstbit (x, bit) != 0)
-		{
-		  printf ("check_single(): expected 0\n");
-		  abort ();
-		}
-
-	      mpz_setbit (x, bit);
-	      MPZ_CHECK_FORMAT (x);
-	      if (mpz_tstbit (x, bit) != 1)
-		{
-		  printf ("check_single(): expected 1\n");
-		  abort ();
-		}
-
-	      mpz_clrbit (x, bit);
-	      MPZ_CHECK_FORMAT (x);
-	      if (mpz_tstbit (x, bit) != 0)
-		{
-		  printf ("check_single(): expected 0\n");
-		  abort ();
-		}
-
-	      mpz_combit (x, bit);
-	      MPZ_CHECK_FORMAT (x);
-	      if (mpz_tstbit (x, bit) != 1)
-		{
-		  printf ("check_single(): expected 1\n");
-		  abort ();
-		}
-
-	      mpz_combit (x, bit);


More information about the gmp-commit mailing list