[Gmp-commit] /var/hg/gmp: Clarify input requirements for mpn_gcd and mpn_gcdext

mercurial at gmplib.org mercurial at gmplib.org
Tue May 17 23:06:47 CEST 2011


details:   /var/hg/gmp/rev/71efb0367192
changeset: 14185:71efb0367192
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Tue May 17 23:05:59 2011 +0200
description:
Clarify input requirements for mpn_gcd and mpn_gcdext

diffstat:

 ChangeLog            |   9 +++++++++
 doc/gmp.texi         |  10 +++++-----
 mpn/generic/gcd.c    |   4 ++++
 mpn/generic/gcdext.c |   1 +
 4 files changed, 19 insertions(+), 5 deletions(-)

diffs (68 lines):

diff -r c8c86b9ffe1f -r 71efb0367192 ChangeLog
--- a/ChangeLog	Sun May 15 22:04:11 2011 +0200
+++ b/ChangeLog	Tue May 17 23:05:59 2011 +0200
@@ -1,3 +1,12 @@
+2011-05-17  Niels Möller  <nisse at lysator.liu.se>
+
+	* doc/gmp.texi (mpn_gcd, mpn_gcdext): Document input requirements:
+	Must have un >= vn > 0, and V normalized.
+	* mpn/generic/gcdext.c (mpn_gcdext): Added ASSERT for input
+	normalization.
+	* mpn/generic/gcd.c (mpn_gcd): Added ASSERTs for input
+	requirements.
+
 2011-05-15  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (operator<<): Dedup.
diff -r c8c86b9ffe1f -r 71efb0367192 doc/gmp.texi
--- a/doc/gmp.texi	Sun May 15 22:04:11 2011 +0200
+++ b/doc/gmp.texi	Tue May 17 23:05:59 2011 +0200
@@ -5357,10 +5357,9 @@
 the return value is the actual number produced.  Both source operands are
 destroyed.
 
-@{@var{xp}, @var{xn}@} must have at least as many bits as @{@var{yp},
- at var{yn}@}.  @{@var{yp}, @var{yn}@} must be odd.  Both operands must have
-non-zero most significant limbs.  No overlap is permitted between @{@var{xp},
- at var{xn}@} and @{@var{yp}, @var{yn}@}.
+It is required that @math{@var{xn} @ge @var{yn} > 0}, and the most significant
+limb of @{@var{yp}, @var{yn}@} must be non-zero.  No overlap is permitted
+between @{@var{xp}, @var{xn}@} and @{@var{yp}, @var{yn}@}.
 @end deftypefun
 
 @deftypefun mp_limb_t mpn_gcd_1 (const mp_limb_t *@var{xp}, mp_size_t @var{xn}, mp_limb_t @var{ylimb})
@@ -5376,7 +5375,8 @@
 a cofactor @math{S} such that @math{G = US + VT}.  The second cofactor @var{T}
 is not computed but can easily be obtained from @m{(G - US) / V, (@var{G} -
 @var{U}*@var{S}) / @var{V}} (the division will be exact).  It is required that
- at math{U @ge V > 0}.
+ at math{@var{un} @ge @var{vn} > 0}, and the most significant
+limb of @{@var{vp}, @var{vn}@} must be non-zero.
 
 @math{S} satisfies @math{S = 1} or @math{@GMPabs{S} < V / (2 G)}. @math{S =
 0} if and only if @math{V} divides @math{U} (i.e., @math{G = V}).
diff -r c8c86b9ffe1f -r 71efb0367192 mpn/generic/gcd.c
--- a/mpn/generic/gcd.c	Sun May 15 22:04:11 2011 +0200
+++ b/mpn/generic/gcd.c	Tue May 17 23:05:59 2011 +0200
@@ -132,6 +132,10 @@
   mp_ptr tp;
   TMP_DECL;
 
+  ASSERT (usize >= n);
+  ASSERT (n > 0);
+  ASSERT (vp[n-1] > 0);
+
   /* FIXME: Check for small sizes first, before setting up temporary
      storage etc. */
   talloc = MPN_GCD_SUBDIV_STEP_ITCH(n);
diff -r c8c86b9ffe1f -r 71efb0367192 mpn/generic/gcdext.c
--- a/mpn/generic/gcdext.c	Sun May 15 22:04:11 2011 +0200
+++ b/mpn/generic/gcdext.c	Tue May 17 23:05:59 2011 +0200
@@ -205,6 +205,7 @@
 
   ASSERT (an >= n);
   ASSERT (n > 0);
+  ASSERT (bp[n-1] > 0);
 
   TMP_MARK;
 


More information about the gmp-commit mailing list