summaryrefslogtreecommitdiff
path: root/mpz/gcdext.c
diff options
context:
space:
mode:
authortege <tege@gmplib.org>1997-07-25 19:14:17 +0200
committertege <tege@gmplib.org>1997-07-25 19:14:17 +0200
commit419364d49f82f767e38bd5fa91c6cbd5ef0107ef (patch)
tree6d0dfb0cf88f1d8808b23b486cf6e84db7a77ff8 /mpz/gcdext.c
parentba13f2a5cacee76ceb83fa7a03ee93fb59e519cd (diff)
downloadgmp-419364d49f82f767e38bd5fa91c6cbd5ef0107ef.tar.gz
Get cofactor sign right for negative input operands.
Clean up code for computing tt.
Diffstat (limited to 'mpz/gcdext.c')
-rw-r--r--mpz/gcdext.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/mpz/gcdext.c b/mpz/gcdext.c
index 8b600a0f3..9c032b617 100644
--- a/mpz/gcdext.c
+++ b/mpz/gcdext.c
@@ -1,7 +1,7 @@
/* mpz_gcdext(g, s, t, a, b) -- Set G to gcd(a, b), and S and T such that
g = as + bt.
-Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
+Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -114,19 +114,20 @@ mpz_gcdext (g, s, t, a, b)
}
sp = PTR (ss);
MPN_COPY (sp, tmp_sp, ssize);
- SIZ (ss) = tmp_ssize >= 0 ? ssize : -ssize;
+ SIZ (ss) = (tmp_ssize ^ SIZ (u)) >= 0 ? ssize : -ssize;
if (tt != NULL)
{
- mpz_t x;
- MPZ_TMP_INIT (x, ssize + usize + 1);
-
- mpz_mul (x, ss, u);
- mpz_sub (x, g, x);
if (SIZ (v) == 0)
SIZ (tt) = 0;
else
- mpz_tdiv_q (tt, x, v);
+ {
+ mpz_t x;
+ MPZ_TMP_INIT (x, ssize + usize + 1);
+ mpz_mul (x, ss, u);
+ mpz_sub (x, g, x);
+ mpz_tdiv_q (tt, x, v);
+ }
}
TMP_FREE (marker);