[Gmp-commit] /var/hg/gmp: Allow mpz_gcdext (NULL, ...)

mercurial at gmplib.org mercurial at gmplib.org
Fri Nov 25 13:08:20 UTC 2016


details:   /var/hg/gmp/rev/5ed3adc694e1
changeset: 17136:5ed3adc694e1
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Fri Nov 25 14:08:18 2016 +0100
description:
Allow mpz_gcdext (NULL, ...)

diffstat:

 ChangeLog         |   6 ++++++
 doc/gmp.texi      |   2 +-
 mpz/gcdext.c      |  19 ++++++++++++-------
 tests/mpz/t-gcd.c |  11 +++++++++++
 4 files changed, 30 insertions(+), 8 deletions(-)

diffs (82 lines):

diff -r 504ea841a52b -r 5ed3adc694e1 ChangeLog
--- a/ChangeLog	Fri Nov 25 00:14:18 2016 +0100
+++ b/ChangeLog	Fri Nov 25 14:08:18 2016 +0100
@@ -1,3 +1,9 @@
+2016-11-25  Marc Glisse  <marc.glisse at inria.fr>
+
+	* mpz/gcdext.c (mpz_gcdext): Allow a first argument of NULL.
+	* doc/gmp.texi (Number Theoretic Functions): Document it.
+	* tests/mpz/t-gcd.c (main): Test it.
+
 2016-11-25  Marc Glisse  <marc.glisse at inria.fr>
 
 	* tests/cxx/t-ops2z.cc (checkz): Avoid left shift of negative number.
diff -r 504ea841a52b -r 5ed3adc694e1 doc/gmp.texi
--- a/doc/gmp.texi	Fri Nov 25 00:14:18 2016 +0100
+++ b/doc/gmp.texi	Fri Nov 25 14:08:18 2016 +0100
@@ -3624,7 +3624,7 @@
 @GMPabs{@var{b}}}, i.e., if @var{b} divides @var{a} or @math{@var{a} = @var{b}
 = 0}.
 
-If @var{t} is @code{NULL} then that value is not computed.
+If @var{s}, @var{t} or @var{g} is @code{NULL} then that value is not computed.
 @end deftypefun
 
 @deftypefun void mpz_lcm (mpz_t @var{rop}, const mpz_t @var{op1}, const mpz_t @var{op2})
diff -r 504ea841a52b -r 5ed3adc694e1 mpz/gcdext.c
--- a/mpz/gcdext.c	Fri Nov 25 00:14:18 2016 +0100
+++ b/mpz/gcdext.c	Fri Nov 25 14:08:18 2016 +0100
@@ -62,10 +62,12 @@
       /* g = |a|, s = sgn(a), t = 0. */
       ssize = SIZ (a) >= 0 ? (asize != 0) : -1;
 
-      gp = MPZ_REALLOC (g, asize);
-      MPN_COPY (gp, PTR (a), asize);
-      SIZ (g) = asize;
-
+      if (g != NULL)
+	{
+	  gp = MPZ_REALLOC (g, asize);
+	  MPN_COPY (gp, PTR (a), asize);
+	  SIZ (g) = asize;
+	}
       if (t != NULL)
 	SIZ (t) = 0;
       if (s != NULL)
@@ -115,9 +117,12 @@
       SIZ (s) = tmp_ssize;
     }
 
-  gp = MPZ_REALLOC (g, gsize);
-  MPN_COPY (gp, tmp_gp, gsize);
-  SIZ (g) = gsize;
+  if (g != NULL)
+    {
+      gp = MPZ_REALLOC (g, gsize);
+      MPN_COPY (gp, tmp_gp, gsize);
+      SIZ (g) = gsize;
+    }
 
   TMP_FREE;
 }
diff -r 504ea841a52b -r 5ed3adc694e1 tests/mpz/t-gcd.c
--- a/tests/mpz/t-gcd.c	Fri Nov 25 00:14:18 2016 +0100
+++ b/tests/mpz/t-gcd.c	Fri Nov 25 14:08:18 2016 +0100
@@ -287,6 +287,17 @@
       one_test (op1, op2, ref, i);
     }
 
+  /* Check that we can use NULL as first argument of mpz_gcdext.  */
+  mpz_set_si (op1, -10);
+  mpz_set_si (op2, 0);
+  mpz_gcdext (NULL, temp1, temp2, op1, op2);
+  ASSERT_ALWAYS (mpz_cmp_si (temp1, -1) == 0);
+  ASSERT_ALWAYS (mpz_cmp_si (temp2, 0) == 0);
+  mpz_set_si (op2, 6);
+  mpz_gcdext (NULL, temp1, temp2, op1, op2);
+  ASSERT_ALWAYS (mpz_cmp_si (temp1, 1) == 0);
+  ASSERT_ALWAYS (mpz_cmp_si (temp2, 2) == 0);
+
   mpz_clears (bs, op1, op2, ref, gcd1, gcd2, temp1, temp2, temp3, s, NULL);
 
   tests_end ();


More information about the gmp-commit mailing list