[Gmp-commit] /home/hgfiles/gmp: Also generate inputs with large quotients and...

mercurial at gmplib.org mercurial at gmplib.org
Tue Mar 9 16:56:22 CET 2010


details:   /home/hgfiles/gmp/rev/b59c19bae17f
changeset: 13474:b59c19bae17f
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Tue Mar 09 16:56:13 2010 +0100
description:
Also generate inputs with large quotients and a large gcd.

diffstat:

 ChangeLog         |   5 ++++
 tests/mpz/t-jac.c |  62 ++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 48 insertions(+), 19 deletions(-)

diffs (109 lines):

diff -r 3d137583d554 -r b59c19bae17f ChangeLog
--- a/ChangeLog	Tue Mar 09 07:04:13 2010 +0100
+++ b/ChangeLog	Tue Mar 09 16:56:13 2010 +0100
@@ -1,3 +1,8 @@
+2010-03-09  Niels Möller  <nisse at lysator.liu.se>
+
+	* tests/mpz/t-jac.c (check_large_quotients): Also generate inputs
+	with large quotients and a large gcd.
+
 2010-03-09 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* tests/mpz/t-bin.c (randomwalk): New test-generator function.
diff -r 3d137583d554 -r b59c19bae17f tests/mpz/t-jac.c
--- a/tests/mpz/t-jac.c	Tue Mar 09 07:04:13 2010 +0100
+++ b/tests/mpz/t-jac.c	Tue Mar 09 16:56:13 2010 +0100
@@ -847,6 +847,11 @@
   mpz_t step;
   TMP_SDECL;
 
+  ASSERT_ALWAYS (mpz_sgn (step_in) > 0);
+
+  /* Negative n could be supported, but currently aren't. */
+  ASSERT_ALWAYS (mpz_sgn (n) >= 0);
+
   mpz_init (step);
 
   switch ( (mpz_odd_p (n) << 1) + mpz_odd_p (step_in))
@@ -951,7 +956,7 @@
 void
 check_large_quotients (void)
 {
-#define COUNT 3
+#define COUNT 4
 #define MAX_THRESHOLD 30
 
   gmp_randstate_ptr rands = RANDS;
@@ -969,13 +974,27 @@
       unsigned j;
       unsigned chain_len;
       int answer;
+      mp_bitcnt_t gcd_size;
+
+      /* Code originally copied from t-gcd.c */
+      mpz_set_ui (op1, 0);
+      mpz_urandomb (bs, rands, 32);
+      mpz_urandomb (bs, rands, mpz_get_ui (bs) % 12 + 1);
       
-      /* Code copied from t-gcd.c */
-      mpz_set_ui (op1, 0);
-      mpz_set_ui (op2, 1);
-      
+      gcd_size = 1 + mpz_get_ui (bs);
+      if (gcd_size & 1)
+	{
+	  gcd_size = 0;
+	  mpz_set_ui (op2, 1);
+	}
+      else
+	{
+	  mpz_rrandomb (op2, rands, gcd_size);
+	  mpz_add_ui (op2, op2, 2);
+	}
+
       mpz_urandomb (bs, rands, 32);
-      chain_len = mpz_get_ui (bs) % (GMP_NUMB_BITS * MAX_THRESHOLD / 256);
+      chain_len = 1 + mpz_get_ui (bs) % (GMP_NUMB_BITS * MAX_THRESHOLD / 256);
 
       for (j = 0; j < chain_len; j++)
 	{
@@ -1006,21 +1025,26 @@
 	}
       ASSERT_ALWAYS (mpz_cmp (op1, op2) < 0);
 
-      if (mpz_odd_p (op1) && mpz_probab_prime_p (op1, 5))
-	{
-	  answer = refmpz_legendre (op2, op1);
-	  try_all (op2, op1, answer);
-	}
-      else if (mpz_odd_p (op2) && mpz_probab_prime_p (op2, 5))
-	{
-	  answer = refmpz_legendre (op1, op2);
-	  try_all (op1, op2, answer);
-	}
+      if (gcd_size)
+	try_all (op2, op1, 0);
       else
 	{
-	  mpz_nextprime_step (op1, op2, op1);
-	  answer = refmpz_legendre (op2, op1);
-	  try_all (op2, op1, answer);
+	  if (mpz_odd_p (op1) && mpz_probab_prime_p (op1, 5))
+	    {
+	      answer = refmpz_legendre (op2, op1);
+	      try_all (op2, op1, answer);
+	    }
+	  else if (mpz_odd_p (op2) && mpz_probab_prime_p (op2, 5))
+	    {
+	      answer = refmpz_legendre (op1, op2);
+	      try_all (op1, op2, answer);
+	    }
+	  else
+	    {
+	      mpz_nextprime_step (op1, op2, op1);
+	      answer = refmpz_legendre (op2, op1);
+	      try_all (op2, op1, answer);
+	    }
 	}
     }
   mpz_clear (op1);


More information about the gmp-commit mailing list