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

mercurial at gmplib.org mercurial at gmplib.org
Fri Jan 31 17:11:24 UTC 2020


details:   /var/hg/gmp/rev/d9ae2f58ff31
changeset: 18027:d9ae2f58ff31
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jan 31 17:56:25 2020 +0100
description:
tests/mpz/t-powm.c: more tests for the base==2 case.

details:   /var/hg/gmp/rev/6c062a1cad34
changeset: 18028:6c062a1cad34
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jan 31 18:11:13 2020 +0100
description:
ChangeLog

diffstat:

 ChangeLog          |   6 +++++
 tests/mpz/t-powm.c |  59 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 61 insertions(+), 4 deletions(-)

diffs (103 lines):

diff -r 63e53ddfd210 -r 6c062a1cad34 ChangeLog
--- a/ChangeLog	Fri Jan 31 17:31:42 2020 +0100
+++ b/ChangeLog	Fri Jan 31 18:11:13 2020 +0100
@@ -1,3 +1,9 @@
+2020-01-31 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpn/generic/powm.c (MPN_REDC_0): Subtractive redc
+	(mpn_2powm): New, static, function
+	* tests/mpz/t-powm.c: More tests for the base=2 case.
+
 2020-01-24  Niels Möller  <nisse at lysator.liu.se>
 
 	* mpn/generic/hgcd2_jacobi.c (div1, div2): Deleted. Instead,
diff -r 63e53ddfd210 -r 6c062a1cad34 tests/mpz/t-powm.c
--- a/tests/mpz/t-powm.c	Fri Jan 31 17:31:42 2020 +0100
+++ b/tests/mpz/t-powm.c	Fri Jan 31 18:11:13 2020 +0100
@@ -42,6 +42,51 @@
   return 1;
 }
 
+void
+small_2pow (unsigned long reps)
+{
+  mpz_t du, exp, mod;
+  mpz_t r1;
+  unsigned long m, e, r;
+  mp_limb_t b0 = 2;
+
+  mpz_roinit_n (du, &b0, 1);
+  mpz_init (exp);
+  mpz_init (mod);
+  mpz_init (r1);
+
+  for (m = 3; m * m < reps; m += 2)
+    {
+      mpz_set_ui (mod, m);
+      r = 1;
+      for (e = 0; e < m; e += 1)
+	{
+	  mpz_set_ui (exp, e);
+	  mpz_powm (r1, du, exp, mod);
+	  MPZ_CHECK_FORMAT (r1);
+	  if (mpz_cmp_ui (r1, r) != 0)
+	    {
+	      fprintf (stderr, "\nIncorrect result for operands:\n");
+	      debug_mp (du, -16);
+	      debug_mp (exp, -16);
+	      debug_mp (mod, -16);
+	      fprintf (stderr, "mpz_powm result:\n");
+	      debug_mp (r1, -16);
+	      fprintf (stderr, "Should be 2 ^ 0x%lx = 0x%lx (mod 0x%lx)\n", e, r, m);
+	      abort ();
+	    }
+	  if (r > (m >> 1))
+	    r = (r << 1) - m;
+	  else
+	    r = r << 1;
+	}
+    }
+
+  mpz_clear (exp);
+  mpz_clear (mod);
+  mpz_clear (r1);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -58,6 +103,7 @@
   tests_start ();
   TESTS_REPS (reps, argv, argc);
 
+  small_2pow ((unsigned int) reps);
   rands = RANDS;
 
   mpz_init (bs);
@@ -99,7 +145,7 @@
 	  mpz_urandomb (bs, rands, size_range);
 	  mod_size = mpz_get_ui (bs) + base_size + 2;
 	  if ((i & 8) == 0)
-	    mod_size += (GMP_NUMB_BITS - mod_size) % GMP_NUMB_BITS;
+	    mod_size += GMP_NUMB_BITS - mod_size % GMP_NUMB_BITS;
 	  mpz_setbit (mod, mod_size);
 
 	  mpz_sub (base, base, mod);
@@ -108,9 +154,14 @@
 	{
       do  /* Loop until mathematically well-defined.  */
 	{
-	  mpz_urandomb (bs, rands, size_range);
-	  base_size = mpz_get_ui (bs);
-	  mpz_rrandomb (base, rands, base_size);
+	  if ((i & 7) == 4)
+	    mpz_set_ui (base, 2);
+	  else
+	    {
+	      mpz_urandomb (bs, rands, size_range);
+	      base_size = mpz_get_ui (bs);
+	      mpz_rrandomb (base, rands, base_size);
+	    }
 
 	  mpz_urandomb (bs, rands, 7L);
 	  exp_size = mpz_get_ui (bs);


More information about the gmp-commit mailing list