1 /* Test mpz_gcd, mpz_gcdext, mpz_mul, mpz_tdiv_r, mpz_add, mpz_cmp,
2 mpz_cmp_ui, mpz_init_set, mpz_set, mpz_clear.
4 Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Library General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16 License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
28 void mpz_refgcd (), debug_mp ();
39 mpz_t refgcd, gcd, s, t;
41 mp_size_t op1_size, op2_size, x_size;
46 reps = atoi (argv[1]);
58 for (i = 0; i < reps; i++)
60 op1_size = urandom () % SIZE - SIZE/2;
61 op2_size = urandom () % SIZE - SIZE/2;
62 x_size = urandom () % SIZE/2;
64 mpz_random2 (op1, op1_size);
65 mpz_random2 (op2, op2_size);
66 mpz_random2 (x, x_size);
67 mpz_mul (op1, op1, x);
68 mpz_mul (op2, op2, x);
70 mpz_refgcd (refgcd, op1, op2);
72 mpz_gcd (gcd, op1, op2);
73 if (mpz_cmp (refgcd, gcd))
74 dump_abort (op1, op2);
76 mpz_gcdext (gcd, s, t, op1, op2);
77 if (mpz_cmp (refgcd, gcd))
78 dump_abort (op1, op2);
80 mpz_mul (temp1, s, op1);
81 mpz_mul (temp2, t, op2);
82 mpz_add (gcd, temp1, temp2);
83 if (mpz_cmp (refgcd, gcd))
84 dump_abort (op1, op2);
105 if (mpz_cmp_ui (yy, 0) == 0)
110 mpz_tdiv_r (xx, xx, yy);
111 if (mpz_cmp_ui (xx, 0) == 0)
116 mpz_tdiv_r (yy, yy, xx);
123 dump_abort (op1, op2)
126 fprintf (stderr, "ERROR\n");
127 fprintf (stderr, "op1 = "); debug_mp (op1, -16);
128 fprintf (stderr, "op2 = "); debug_mp (op2, -16);
136 mpz_out_str (stderr, base, x); fputc ('\n', stderr);