summaryrefslogtreecommitdiff
path: root/mpz
diff options
context:
space:
mode:
authortege <tege@gmplib.org>1999-03-14 02:25:35 +0100
committertege <tege@gmplib.org>1999-03-14 02:25:35 +0100
commit4c0ee1bb49fbb0e8f9d455f8ba7a2910bd064b7f (patch)
tree48e0419e281da40206e54fb5212eefb044cb0fbf /mpz
parent347eacdc0eed64ade2c7f9a06f2f9b0012b465e4 (diff)
downloadgmp-4c0ee1bb49fbb0e8f9d455f8ba7a2910bd064b7f.tar.gz
Also test mpz_invert and mpz_divexact.
Diffstat (limited to 'mpz')
-rw-r--r--mpz/tests/reuse.c56
1 files changed, 42 insertions, 14 deletions
diff --git a/mpz/tests/reuse.c b/mpz/tests/reuse.c
index 52fc5a516..c72024597 100644
--- a/mpz/tests/reuse.c
+++ b/mpz/tests/reuse.c
@@ -15,42 +15,50 @@ typedef void (*dss_func) (mpz_ptr, mpz_srcptr, mpz_srcptr);
typedef void (*dss_func) ();
#endif
+void
+mpz_xinvert (mpz_ptr r, mpz_srcptr a, mpz_srcptr b)
+{
+ int res;
+ res = mpz_invert (r, a, b);
+ if (res == 0)
+ mpz_set_ui (r, 0);
+}
+
dss_func dss_funcs[] =
{
mpz_add, mpz_and, mpz_cdiv_q, mpz_cdiv_r, mpz_fdiv_q, mpz_fdiv_r,
- mpz_gcd, mpz_ior, mpz_mul, mpz_sub, mpz_tdiv_q, mpz_tdiv_r
+ mpz_gcd, mpz_ior, mpz_mul, mpz_sub, mpz_tdiv_q, mpz_tdiv_r, mpz_xinvert
};
char *dss_func_names[] =
{
"mpz_add", "mpz_and", "mpz_cdiv_q", "mpz_cdiv_r", "mpz_fdiv_q", "mpz_fdiv_r",
- "mpz_gcd", "mpz_ior", "mpz_mul", "mpz_sub", "mpz_tdiv_q", "mpz_tdiv_r"
+ "mpz_gcd", "mpz_ior", "mpz_mul", "mpz_sub", "mpz_tdiv_q", "mpz_tdiv_r",
+ "mpz_xinvert"
};
char dss_func_division[] = {0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1};
-#if 0
-mpz_divexact /* requires special operands */
-#endif
-
main (argc, argv)
int argc;
char **argv;
{
int i;
int pass, reps = 10000;
- mpz_t in1, in2, out1;
+ mpz_t in1, in2, out;
mpz_t res1, res2, res3;
+ mpz_t t;
if (argc == 2)
reps = atoi (argv[1]);
mpz_init (in1);
mpz_init (in2);
- mpz_init (out1);
+ mpz_init (out);
mpz_init (res1);
mpz_init (res2);
mpz_init (res3);
+ mpz_init (t);
for (pass = 1; pass <= reps; pass++)
{
@@ -64,19 +72,39 @@ main (argc, argv)
(dss_funcs[i]) (res1, in1, in2);
- mpz_set (out1, in1);
- (dss_funcs[i]) (out1, out1, in2);
- mpz_set (res2, out1);
+ mpz_set (out, in1);
+ (dss_funcs[i]) (out, out, in2);
+ mpz_set (res2, out);
- mpz_set (out1, in2);
- (dss_funcs[i]) (out1, in1, out1);
- mpz_set (res3, out1);
+ mpz_set (out, in2);
+ (dss_funcs[i]) (out, in1, out);
+ mpz_set (res3, out);
if (mpz_cmp (res1, res2) != 0)
dump_abort (dss_func_names[i], in1, in2);
if (mpz_cmp (res1, res3) != 0)
dump_abort (dss_func_names[i], in1, in2);
}
+
+ if (mpz_cmp_ui (in2, 0) == 0)
+ continue;
+
+ mpz_mul (t, in1, in2);
+
+ mpz_divexact (res1, t, in2);
+
+ mpz_set (out, t);
+ mpz_divexact (out, out, in2);
+ mpz_set (res2, out);
+
+ mpz_set (out, in2);
+ mpz_divexact (out, t, out);
+ mpz_set (res3, out);
+
+ if (mpz_cmp (res1, res2) != 0)
+ dump_abort ("mpz_divexact", t, in2);
+ if (mpz_cmp (res1, res3) != 0)
+ dump_abort ("mpz_divexact", t, in2);
}
exit (0);