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 ();
31 #define SIZE 256 /* really needs to be this large to exercise corner cases! */
39 mpz_t refgcd, gcd, s, t;
41 mp_size_t op1_size, op2_size;
46 reps = atoi (argv[1]);
57 for (i = 0; i < reps; i++)
59 op1_size = urandom () % SIZE - SIZE/2;
60 op2_size = urandom () % SIZE - SIZE/2;
62 mpz_random2 (op1, op1_size);
63 mpz_random2 (op2, op2_size);
65 mpz_refgcd (refgcd, op1, op2);
67 mpz_gcd (gcd, op1, op2);
68 if (mpz_cmp (refgcd, gcd))
69 dump_abort (op1, op2);
71 mpz_gcdext (gcd, s, t, op1, op2);
72 if (mpz_cmp (refgcd, gcd))
73 dump_abort (op1, op2);
75 mpz_mul (temp1, s, op1);
76 mpz_mul (temp2, t, op2);
77 mpz_add (gcd, temp1, temp2);
78 if (mpz_cmp (refgcd, gcd))
79 dump_abort (op1, op2);
100 if (mpz_cmp_ui (yy, 0) == 0)
105 mpz_tdiv_r (xx, xx, yy);
106 if (mpz_cmp_ui (xx, 0) == 0)
111 mpz_tdiv_r (yy, yy, xx);
118 dump_abort (op1, op2)
121 fprintf (stderr, "ERROR\n");
122 fprintf (stderr, "op1 = "); debug_mp (op1, -16);
123 fprintf (stderr, "op2 = "); debug_mp (op2, -16);
131 mpz_out_str (stderr, base, x); fputc ('\n', stderr);