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

mercurial at gmplib.org mercurial at gmplib.org
Tue Dec 11 00:48:16 UTC 2018


details:   /var/hg/gmp/rev/4363a9d338b6
changeset: 17727:4363a9d338b6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Dec 11 01:43:56 2018 +0100
description:
tests/mpz/t-nextprime.c: Use TESTS_REPS

details:   /var/hg/gmp/rev/0f4a32d1b3f3
changeset: 17728:0f4a32d1b3f3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Dec 11 01:44:27 2018 +0100
description:
comment

details:   /var/hg/gmp/rev/c280a9fc13fd
changeset: 17729:c280a9fc13fd
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Dec 11 01:45:08 2018 +0100
description:
mini-gmp/mini-gmp.c: ()

details:   /var/hg/gmp/rev/2f9b32860c31
changeset: 17730:2f9b32860c31
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Dec 11 01:46:32 2018 +0100
description:
bootstrap.c (mpz_invert_ui_2exp): support exotic limb size in mini-

details:   /var/hg/gmp/rev/a96e519c87e3
changeset: 17731:a96e519c87e3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Dec 11 01:47:48 2018 +0100
description:
mini-gmp/tests/t-mpq_addsub.c (testcmpui): One more test

diffstat:

 bootstrap.c                   |  13 +++++++++++--
 mini-gmp/mini-gmp.c           |   4 ++--
 mini-gmp/tests/t-mpq_addsub.c |  40 ++++++++++++++++++++++++++++++++++++++++
 mpz/stronglucas.c             |   4 ++--
 tests/mpz/t-nextprime.c       |   3 +--
 5 files changed, 56 insertions(+), 8 deletions(-)

diffs (125 lines):

diff -r 9a958f8b67e4 -r a96e519c87e3 bootstrap.c
--- a/bootstrap.c	Sun Dec 09 20:28:18 2018 +0100
+++ b/bootstrap.c	Tue Dec 11 01:47:48 2018 +0100
@@ -136,8 +136,17 @@
 
 /* Calculate inv satisfying r*a == 1 mod 2^n. */
 void
-mpz_invert_ui_2exp (mpz_t r, mp_limb_t a, unsigned long n)
+mpz_invert_ui_2exp (mpz_t r, unsigned long a, unsigned long n)
 {
   mpz_t  az;
-  mpz_invert_2exp (r, mpz_roinit_n (az, &a, 1), n);
+
+  if (sizeof (mp_limb_t) == sizeof (unsigned long))
+    mpz_invert_2exp (r, mpz_roinit_n (az, (mp_srcptr) &a, 1), n);
+  else
+    {
+      mpz_init_set_ui (az, a);
+      mpz_invert_2exp (r, az, n);
+      mpz_clear (az);
+    }
+
 }
diff -r 9a958f8b67e4 -r a96e519c87e3 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Sun Dec 09 20:28:18 2018 +0100
+++ b/mini-gmp/mini-gmp.c	Tue Dec 11 01:47:48 2018 +0100
@@ -1029,7 +1029,7 @@
 
   if (shift > 0)
     {
-      assert ((r0 & GMP_LIMB_MAX >> GMP_LIMB_BITS - shift) == 0);
+      assert ((r0 & GMP_LIMB_MAX >> (GMP_LIMB_BITS - shift)) == 0);
       r0 = (r0 >> shift) | (r1 << (GMP_LIMB_BITS - shift));
       r1 >>= shift;
     }
@@ -1252,7 +1252,7 @@
       l = w << binv->shift;
 
       gmp_udiv_qrnnd_preinv (w, r, h, l, binv->d1, binv->di);
-      assert ((r & GMP_LIMB_MAX >> GMP_LIMB_BITS - binv->shift) == 0);
+      assert ((r & GMP_LIMB_MAX >> (GMP_LIMB_BITS - binv->shift)) == 0);
       r >>= binv->shift;
 
       sp[i] = r;
diff -r 9a958f8b67e4 -r a96e519c87e3 mini-gmp/tests/t-mpq_addsub.c
--- a/mini-gmp/tests/t-mpq_addsub.c	Sun Dec 09 20:28:18 2018 +0100
+++ b/mini-gmp/tests/t-mpq_addsub.c	Tue Dec 11 01:47:48 2018 +0100
@@ -47,6 +47,45 @@
 }
 
 void
+testcmpui ()
+{
+  unsigned d1, d2, n1, n2;
+  mpq_t q1, q2;
+
+  mpq_init (q1);
+  mpq_init (q2);
+
+  for (d1 = 1; d1 < 6; d1 += 2)
+    for (n1 = 1; n1 < 6; n1 *= 2)
+      {
+	mpq_set_ui (q1, n1, d1);
+	for (d2 = 1; d2 < 6; d2 += 2)
+	  for (n2 = 1; n2 < 6; n2 *= 2)
+	    {
+	      int fres = mpq_cmp_ui (q1, n2, d2);
+	      int ref = (d1*n2 < d2*n1) - (d1*n2 > d2*n1);
+
+	      mpq_set_ui (q2, n2, d2);
+
+	      if (!ref != mpq_equal (q1, q2))
+		{
+		  fprintf (stderr, "mpz_equal failed: %i / %i = %i / %i ? %i\n", n1, d1, n2, d2, ref);
+		  abort ();
+		}
+
+	      if (ref != fres)
+		{
+		  fprintf (stderr, "mpz_cmp_ui failed: %i / %i = %i / %i ? %i != %i\n", n1, d1, n2, d2, ref, fres);
+		  abort ();
+		}
+	    }
+      }
+
+  mpq_clear (q1);
+  mpq_clear (q2);
+}
+
+void
 testmain (int argc, char **argv)
 {
   unsigned i;
@@ -54,6 +93,7 @@
   mpq_t rr, ii, ff;
   int tst;
 
+  testcmpui ();
   mpz_init (a);
   mpz_init (b);
   mpz_init (r);
diff -r 9a958f8b67e4 -r a96e519c87e3 mpz/stronglucas.c
--- a/mpz/stronglucas.c	Sun Dec 09 20:28:18 2018 +0100
+++ b/mpz/stronglucas.c	Tue Dec 11 01:47:48 2018 +0100
@@ -1,5 +1,5 @@
-/* mpz_stronglucas(n,reps) -- An implementation of the strong Lucas
-   primality test, using parameters as suggested by the BPSW test.
+/* mpz_stronglucas(n, t1, t2) -- An implementation of the strong Lucas
+   primality test on n, using parameters as suggested by the BPSW test.
 
    THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY.  THEY'RE ALMOST
    CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
diff -r 9a958f8b67e4 -r a96e519c87e3 tests/mpz/t-nextprime.c
--- a/tests/mpz/t-nextprime.c	Sun Dec 09 20:28:18 2018 +0100
+++ b/tests/mpz/t-nextprime.c	Tue Dec 11 01:47:48 2018 +0100
@@ -106,8 +106,7 @@
   mpz_init (nxtp);
   mpz_init (ref_nxtp);
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   for (i = 0; i < reps; i++)
     {


More information about the gmp-commit mailing list