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

mercurial at gmplib.org mercurial at gmplib.org
Fri Feb 24 17:45:58 CET 2012


details:   /var/hg/gmp/rev/f818ada9ec44
changeset: 14675:f818ada9ec44
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Feb 24 17:39:21 2012 +0100
description:
Typos.

details:   /var/hg/gmp/rev/ac67d45cb24e
changeset: 14676:ac67d45cb24e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Feb 24 17:40:57 2012 +0100
description:
mpz_invert: return 0 (no-inverse) when modulus is zero.

details:   /var/hg/gmp/rev/c6f02336b749
changeset: 14677:c6f02336b749
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Feb 24 17:42:00 2012 +0100
description:
tests/mpz/t-invert.c: test format, range, and correctes of the "no-inverse" answer.

details:   /var/hg/gmp/rev/b3d04bbfafa7
changeset: 14678:b3d04bbfafa7
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Feb 24 17:45:54 2012 +0100
description:
Changelog entries

diffstat:

 ChangeLog            |  22 +++++++++++++---------
 doc/gmp.texi         |   2 +-
 mpz/invert.c         |   4 ++--
 tests/mpn/logic.c    |   2 +-
 tests/mpz/t-invert.c |  29 ++++++++++++++++++++++++++---
 5 files changed, 43 insertions(+), 16 deletions(-)

diffs (131 lines):

diff -r 566b3502421d -r b3d04bbfafa7 ChangeLog
--- a/ChangeLog	Fri Feb 24 14:53:19 2012 +0100
+++ b/ChangeLog	Fri Feb 24 17:45:54 2012 +0100
@@ -1,3 +1,15 @@
+2012-02-24 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/invert.c: Use ABSIZ, MPZ_EQUAL_1_P.
+	* mpz/abs.c: Collapse MPZ_REALLOC(x,.) and PTR(x).
+	* mpz/aors_ui.h: Likewise.
+	* mpz/com.c: Likewise.
+        * mpz/neg.c: Likewise.
+
+	* mpz/invert.c: Reply "no-inverse" when modulus is zero.
+	* tests/mpz/t-invert.c: Add more checks.
+	* doc/gmp.texi (mpz_invert): Inverse can not be zero.
+
 2012-02-24  Torbjorn Granlund  <tege at gmplib.org>
 
 	* tests/mpn/logic.c: New file.
@@ -6,7 +18,7 @@
 	* tests/mpz/t-invert.c: New file.
 	* tests/mpz/Makefile.am (check_PROGRAMS): Add t-invert.
 
-2012-02-23  Marc Glisse  <marc.glisse at inria.fr>
+2012-02-24  Marc Glisse  <marc.glisse at inria.fr>
 
 	* tests/mpq/t-cmp.c: Move NUM and DEN macros...
 	* tests/mpq/t-cmp_ui.c: Likewise...
@@ -56,14 +68,6 @@
 	* mpn/x86_64/core2/aorsmul_1.asm: Added mpn_addmul_1c and
 	mpn_submul_1c entry points.
 
-2012-02-24 Marco Bodrato <bodrato at mail.dm.unipi.it>
-
-	* mpz/invert.c: Use ABSIZ, MPZ_EQUAL_1_P.
-	* mpz/abs.c: Collapse MPZ_REALLOC(x,.) and PTR(x).
-	* mpz/aors_ui.h: Likewise.
-	* mpz/com.c: Likewise.
-        * mpz/neg.c: Likewise.
-
 2012-02-23  Marc Glisse  <marc.glisse at inria.fr>
 
 	* mpz/abs.c: Use ALLOC, SIZ, ABSIZ, PTR, MPZ_REALLOC.
diff -r 566b3502421d -r b3d04bbfafa7 doc/gmp.texi
--- a/doc/gmp.texi	Fri Feb 24 14:53:19 2012 +0100
+++ b/doc/gmp.texi	Fri Feb 24 17:45:54 2012 +0100
@@ -3585,7 +3585,7 @@
 @cindex Inverse modulo functions
 Compute the inverse of @var{op1} modulo @var{op2} and put the result in
 @var{rop}.  If the inverse exists, the return value is non-zero and @var{rop}
-will satisfy @math{0 @le{} @var{rop} < @var{op2}}.  If an inverse doesn't exist
+will satisfy @math{0 < @var{rop} < @var{op2}}.  If an inverse doesn't exist
 the return value is zero and @var{rop} is undefined.
 @end deftypefun
 
diff -r 566b3502421d -r b3d04bbfafa7 mpz/invert.c
--- a/mpz/invert.c	Fri Feb 24 14:53:19 2012 +0100
+++ b/mpz/invert.c	Fri Feb 24 17:45:54 2012 +0100
@@ -34,8 +34,8 @@
   nsize = ABSIZ (n);
 
   /* No inverse exists if the leftside operand is 0.  Likewise, no
-     inverse exists if the mod operand is 1.  */
-  if (xsize == 0 || (nsize == 1 && (PTR (n))[0] == 1))
+     inverse exists if the mod operand is 1 or 0.  */
+  if (xsize == 0 || nsize == 0 || (nsize == 1 && (PTR (n))[0] == 1))
     return 0;
 
   size = MAX (xsize, nsize) + 1;
diff -r 566b3502421d -r b3d04bbfafa7 tests/mpn/logic.c
--- a/tests/mpn/logic.c	Fri Feb 24 14:53:19 2012 +0100
+++ b/tests/mpn/logic.c	Fri Feb 24 17:45:54 2012 +0100
@@ -1,4 +1,4 @@
-/* Test mpn_and, mpn_ior, mpn_xor, mpn_andm, mpn_iorn, mpn_xnor, mpn_nand, and
+/* Test mpn_and, mpn_ior, mpn_xor, mpn_andn, mpn_iorn, mpn_xnor, mpn_nand, and
    mpn_nior.
 
 Copyright 2011, 2012 Free Software Foundation, Inc.
diff -r 566b3502421d -r b3d04bbfafa7 tests/mpz/t-invert.c
--- a/tests/mpz/t-invert.c	Fri Feb 24 14:53:19 2012 +0100
+++ b/tests/mpz/t-invert.c	Fri Feb 24 17:45:54 2012 +0100
@@ -56,9 +56,6 @@
       mpz_urandomb (bs, rands, size_range);
       mpz_rrandomb (m, rands, mpz_get_ui (bs));
 
-      if (mpz_sgn (m) == 0)
-	continue;
-
       mpz_urandomb (bs, rands, 8);
       bsi = mpz_get_ui (bs);
 
@@ -70,6 +67,17 @@
       r = mpz_invert (ainv, a, m);
       if (r != 0)
 	{
+	  MPZ_CHECK_FORMAT (ainv);
+
+	  if (mpz_cmp_ui (ainv, 0) <= 0 || mpz_cmpabs (ainv, m) > 0)
+	    {
+	      fprintf (stderr, "ERROR in test %d\n", test);
+	      gmp_fprintf (stderr, "Inverse out of range.\n");
+	      gmp_fprintf (stderr, "a = %Zx\n", a);
+	      gmp_fprintf (stderr, "m = %Zx\n", m);
+	      abort ();
+	    }
+
 	  mpz_mul (t, ainv, a);
 	  mpz_mod (t, t, m);
 
@@ -82,6 +90,21 @@
 	      abort ();
 	    }
 	}
+      else /* Inverse deos not exist */
+	{
+	  if (mpz_cmpabs_ui (m, 1) <= 0)
+	    continue; /* OK */
+
+	  mpz_gcd (t, a, m);
+	  if (mpz_cmp_ui (t, 1) == 0)
+	    {
+	      fprintf (stderr, "ERROR in test %d\n", test);
+	      gmp_fprintf (stderr, "Inverse exists, but was not found.\n");
+	      gmp_fprintf (stderr, "a = %Zx\n", a);
+	      gmp_fprintf (stderr, "m = %Zx\n", m);
+	      abort ();
+	    }
+	}
     }
 
   mpz_clear (bs);


More information about the gmp-commit mailing list