1 /* Test mpz_com, mpz_and, mpz_ior, and mpz_xor.
3 Copyright 1993, 1994, 1996, 1997, 2001 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
27 void dump_abort __GMP_PROTO (());
28 void debug_mp __GMP_PROTO ((mpz_t, int));
31 main (int argc, char **argv)
35 mp_size_t xsize, ysize;
38 gmp_randstate_ptr rands;
40 unsigned long bsi, size_range;
48 reps = atoi (argv[1]);
58 for (i = 0; i < reps; i++)
60 mpz_urandomb (bs, rands, 32);
61 size_range = mpz_get_ui (bs) % 8 + 2;
63 mpz_urandomb (bs, rands, size_range);
64 xsize = mpz_get_ui (bs);
65 mpz_rrandomb (x, rands, xsize);
66 mpz_urandomb (bs, rands, 1);
67 bsi = mpz_get_ui (bs);
71 mpz_urandomb (bs, rands, size_range);
72 ysize = mpz_get_ui (bs);
73 mpz_rrandomb (y, rands, ysize);
74 mpz_urandomb (bs, rands, 1);
75 bsi = mpz_get_ui (bs);
80 MPZ_CHECK_FORMAT (r1);
82 MPZ_CHECK_FORMAT (r1);
83 if (mpz_cmp (r1, x) != 0)
87 MPZ_CHECK_FORMAT (r1);
89 MPZ_CHECK_FORMAT (r2);
90 if (mpz_cmp (r2, y) != 0)
94 MPZ_CHECK_FORMAT (t1);
96 MPZ_CHECK_FORMAT (t2);
98 MPZ_CHECK_FORMAT (t3);
100 MPZ_CHECK_FORMAT (r1);
102 MPZ_CHECK_FORMAT (r2);
103 if (mpz_cmp (r1, r2) != 0)
107 MPZ_CHECK_FORMAT (t1);
109 MPZ_CHECK_FORMAT (t2);
110 mpz_ior (t3, t1, t2);
111 MPZ_CHECK_FORMAT (t3);
113 MPZ_CHECK_FORMAT (r1);
115 MPZ_CHECK_FORMAT (r2);
116 if (mpz_cmp (r1, r2) != 0)
120 MPZ_CHECK_FORMAT (t1);
122 MPZ_CHECK_FORMAT (t2);
124 MPZ_CHECK_FORMAT (t3);
125 mpz_and (r1, t1, t3);
126 MPZ_CHECK_FORMAT (r1);
128 MPZ_CHECK_FORMAT (r2);
129 if (mpz_cmp (r1, r2) != 0)
153 debug_mp (mpz_t x, int base)
155 mpz_out_str (stderr, base, x); fputc ('\n', stderr);