[Gmp-commit] /var/hg/gmp: Jacobi bugfix and corresponding test case.

mercurial at gmplib.org mercurial at gmplib.org
Sun May 22 20:31:15 CEST 2011


details:   /var/hg/gmp/rev/6d7da908a2ef
changeset: 14197:6d7da908a2ef
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Sun May 22 20:31:06 2011 +0200
description:
Jacobi bugfix and corresponding test case.

diffstat:

 ChangeLog         |   5 +++++
 mpz/jacobi.c      |  16 +++++-----------
 tests/mpz/t-jac.c |   1 +
 3 files changed, 11 insertions(+), 11 deletions(-)

diffs (73 lines):

diff -r fcdc50208fad -r 6d7da908a2ef ChangeLog
--- a/ChangeLog	Sat May 21 23:49:09 2011 +0200
+++ b/ChangeLog	Sun May 22 20:31:06 2011 +0200
@@ -1,3 +1,8 @@
+2011-05-22  Niels Möller  <nisse at lysator.liu.se>
+
+	* mpz/jacobi.c (mpz_jacobi): Another bugfix for the asize == 1
+	case. Sometimes, powers of two in b were taken into account twice.
+
 2011-05-21  Niels Möller  <nisse at lysator.liu.se>
 
 	* mpz/jacobi.c (mpz_jacobi): The handling of asize == 1 was
diff -r fcdc50208fad -r 6d7da908a2ef mpz/jacobi.c
--- a/mpz/jacobi.c	Sat May 21 23:49:09 2011 +0200
+++ b/mpz/jacobi.c	Sun May 22 20:31:06 2011 +0200
@@ -94,7 +94,6 @@
   JACOBI_STRIP_LOW_ZEROS (result_bit1, alow, bsrcp, bsize, blow);
 
   count_trailing_zeros (btwos, blow);
-  result_bit1 ^= JACOBI_TWOS_U_BIT1(btwos, alow);
   blow >>= btwos;
 
   if (bsize > 1 && btwos > 0)
@@ -116,6 +115,8 @@
 
   if (bsize == 1)
     {
+      result_bit1 ^= JACOBI_TWOS_U_BIT1(btwos, alow);
+
       if (blow == 1)
 	return JACOBI_BIT1_TO_PN (result_bit1);
 
@@ -130,19 +131,11 @@
       /* Logic copied from mpz_ui_kronecker */
       if (alow == 1)
 	return JACOBI_BIT1_TO_PN (result_bit1);  /* (1/b)=1 */
-	
-      if (btwos > 0)
-	{
-	  /* Only bit 1 of blow is used below. */
-	  if (btwos == GMP_NUMB_BITS - 1)
-	    blow = bsrcp[1] << 1;
-	  else
-	    blow >> btwos;
-	}
 
-      else if ( (alow & 1) == 0)
+      if ( (alow & 1) == 0)
 	{
 	  unsigned atwos;
+	  ASSERT (btwos == 0);
 	  count_trailing_zeros (atwos, alow);
 	  alow >>= atwos;
 	  result_bit1 ^= JACOBI_TWOS_U_BIT1 (atwos, blow);
@@ -156,6 +149,7 @@
       JACOBI_MOD_OR_MODEXACT_1_ODD (result_bit1, blow, bsrcp, bsize, alow);
       return mpn_jacobi_base (blow, alow, result_bit1);
     }
+  result_bit1 ^= JACOBI_TWOS_U_BIT1(btwos, alow);
 
   bits = mpn_jacobi_init (alow, blow, (result_bit1>>1) & 1);
 
diff -r fcdc50208fad -r 6d7da908a2ef tests/mpz/t-jac.c
--- a/tests/mpz/t-jac.c	Sat May 21 23:49:09 2011 +0200
+++ b/tests/mpz/t-jac.c	Sun May 22 20:31:06 2011 +0200
@@ -641,6 +641,7 @@
     /* Exersizes the case asize == 1, btwos = 63 in mpz_jacobi
        (relevant when GMP_LIMB_BITS == 64). */
     { "17311973299000934401", "1675975991242824637446753124775689449936871337036614677577044717424700351103148799107651171694863695242089956242888229458836426332300124417011114380886016", 1 },
+    { "3220569220116583677", "41859917623035396746", -1 },
   };
 
   int    i;


More information about the gmp-commit mailing list