[Gmp-commit] /var/hg/gmp: Test additional cases of reuse for mpz_gcd and mpz_...
mercurial at gmplib.org
mercurial at gmplib.org
Fri Dec 2 20:14:27 UTC 2016
details: /var/hg/gmp/rev/8f287aee0205
changeset: 17153:8f287aee0205
user: Niels M?ller <nisse at lysator.liu.se>
date: Fri Dec 02 21:06:53 2016 +0100
description:
Test additional cases of reuse for mpz_gcd and mpz_gcdext.
diffstat:
ChangeLog | 5 +
tests/mpz/reuse.c | 142 ++++++++++++++++++++++++++++-------------------------
2 files changed, 81 insertions(+), 66 deletions(-)
diffs (183 lines):
diff -r e121607cb19e -r 8f287aee0205 ChangeLog
--- a/ChangeLog Thu Dec 01 22:58:00 2016 +0100
+++ b/ChangeLog Fri Dec 02 21:06:53 2016 +0100
@@ -1,3 +1,8 @@
+2016-12-02 Niels Möller <nisse at lysator.liu.se>
+
+ * tests/mpz/reuse.c (main): Test additional cases of reuse for
+ mpz_gcd and mpz_gcdext.
+
2016-11-27 Marco Bodrato <bodrato at mail.dm.unipi.it>
* mpz/gcd.c, mpz/gcdext.c: Use NEWALLOC.
diff -r e121607cb19e -r 8f287aee0205 tests/mpz/reuse.c
--- a/tests/mpz/reuse.c Thu Dec 01 22:58:00 2016 +0100
+++ b/tests/mpz/reuse.c Fri Dec 02 21:06:53 2016 +0100
@@ -467,91 +467,101 @@
MPZ_CHECK_FORMAT (ref2);
MPZ_CHECK_FORMAT (ref3);
+#define GCDEXT_CHECK(t, i1,i2) do { \
+ mpz_gcdext (res1, res2, t ? res3 : NULL, i1, i2); \
+ MPZ_CHECK_FORMAT (res1); \
+ MPZ_CHECK_FORMAT (res2); \
+ MPZ_CHECK_FORMAT (res3); \
+ if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 \
+ || mpz_cmp (ref3, res3) != 0) \
+ FAIL2 (mpz_gcdext, i1, i2, NULL); \
+ } while(0)
+
mpz_set (res1, in1);
- mpz_gcdext (res1, res2, res3, res1, in2);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- MPZ_CHECK_FORMAT (res3);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (1, res1, in2);
mpz_set (res2, in1);
- mpz_gcdext (res1, res2, res3, res2, in2);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- MPZ_CHECK_FORMAT (res3);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (1, res2, in2);
mpz_set (res3, in1);
- mpz_gcdext (res1, res2, res3, res3, in2);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- MPZ_CHECK_FORMAT (res3);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (1, res3, in2);
mpz_set (res1, in2);
- mpz_gcdext (res1, res2, res3, in1, res1);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- MPZ_CHECK_FORMAT (res3);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (1, in1, res1);
mpz_set (res2, in2);
- mpz_gcdext (res1, res2, res3, in1, res2);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- MPZ_CHECK_FORMAT (res3);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (1, in1, res2);
mpz_set (res3, in2);
- mpz_gcdext (res1, res2, res3, in1, res3);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- MPZ_CHECK_FORMAT (res3);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (1, in1, res3);
mpz_set (res1, in1);
- mpz_gcdext (res1, res2, NULL, res1, in2);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ mpz_set (res2, in2);
+ GCDEXT_CHECK (1, res1, res2);
+
+ mpz_set (res1, in1);
+ mpz_set (res3, in2);
+ GCDEXT_CHECK (1, res1, res3);
mpz_set (res2, in1);
- mpz_gcdext (res1, res2, NULL, res2, in2);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ mpz_set (res3, in2);
+ GCDEXT_CHECK (1, res2, res3);
+
+ mpz_set (res2, in1);
+ mpz_set (res1, in2);
+ GCDEXT_CHECK (1, res2, res1);
+
+ mpz_set (res3, in1);
+ mpz_set (res1, in2);
+ GCDEXT_CHECK (1, res3, res1);
+
+ mpz_set (res3, in1);
+ mpz_set (res2, in2);
+ GCDEXT_CHECK(1, res3, res2);
+
+ mpz_set (res1, in1);
+ GCDEXT_CHECK (0, res1, in2);
+
+ mpz_set (res2, in1);
+ GCDEXT_CHECK (0, res2, in2);
mpz_set (res1, in2);
- mpz_gcdext (res1, res2, NULL, in1, res1);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (0, in1, res1);
mpz_set (res2, in2);
- mpz_gcdext (res1, res2, NULL, in1, res2);
- MPZ_CHECK_FORMAT (res1);
- MPZ_CHECK_FORMAT (res2);
- if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
- || mpz_cmp (ref3, res3) != 0)
- FAIL2 (mpz_gcdext, in1, in2, NULL);
+ GCDEXT_CHECK (0, in1, res2);
+#undef GCDEXT_CHECK
+ /* Identical inputs, gcd(in1, in1). Then the result should be
+ gcd = abs(in1), s = 0, t = sgn(in1). */
+ mpz_abs (ref1, in1);
+ mpz_set_ui (ref2, 0);
+ mpz_set_si (ref3, mpz_sgn(in1));
+
+#define GCDEXT_CHECK_SAME(t, i) do { \
+ mpz_gcdext(res1, res2, t ? res3 : NULL, i, i); \
+ MPZ_CHECK_FORMAT (res1); \
+ MPZ_CHECK_FORMAT (res2); \
+ MPZ_CHECK_FORMAT (res3); \
+ if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 \
+ || mpz_cmp (ref3, res3) != 0) \
+ FAIL2 (mpz_gcdext, i, i, NULL); \
+ } while(0)
+
+ mpz_set (res1, in1);
+ GCDEXT_CHECK_SAME (1, res1);
+
+ mpz_set(res2, in1);
+ GCDEXT_CHECK_SAME (1, res2);
+
+ mpz_set(res3, in1);
+ GCDEXT_CHECK_SAME (1, res3);
+
+ mpz_set (res1, in1);
+ GCDEXT_CHECK_SAME (0, res1);
+
+ mpz_set(res2, in1);
+ GCDEXT_CHECK_SAME (0, res2);
+#undef GCDEXT_CHECK_SAME
}
/* Don't run mpz_powm for huge exponents or when undefined. */
More information about the gmp-commit
mailing list