1 /* Tests of mpz_scan0 and mpz_scan1.
3 Copyright 2000, 2001, 2002, 2003 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/. */
28 refmpz_scan (mpz_srcptr z, unsigned long i, int sought)
30 unsigned long z_bits = (unsigned long) ABSIZ(z) * GMP_NUMB_BITS;
34 if (mpz_tstbit (z, i) == sought)
44 refmpz_scan0 (mpz_srcptr z, unsigned long starting_bit)
46 return refmpz_scan (z, starting_bit, 0);
50 refmpz_scan1 (mpz_srcptr z, unsigned long starting_bit)
52 return refmpz_scan (z, starting_bit, 1);
59 static const int offset[] = {
64 int test, neg, sought, oindex, o;
65 mp_size_t size, isize;
66 unsigned long start, got, want;
69 for (test = 0; test < 5; test++)
71 for (size = 0; size < 5; size++)
73 mpz_random2 (z, size);
75 for (neg = 0; neg <= 1; neg++)
80 for (isize = 0; isize <= size; isize++)
82 for (oindex = 0; oindex <= numberof (offset); oindex++)
85 if ((int) isize*GMP_NUMB_BITS < -o)
86 continue; /* start would be negative */
88 start = isize*GMP_NUMB_BITS + o;
90 for (sought = 0; sought <= 1; sought++)
94 got = mpz_scan0 (z, start);
95 want = refmpz_scan0 (z, start);
99 got = mpz_scan1 (z, start);
100 want = refmpz_scan1 (z, start);
105 printf ("wrong at test=%d, size=%ld, neg=%d, start=%lu, sought=%d\n",
106 test, size, neg, start, sought);
108 mpz_out_str (stdout, -16, z);
110 printf (" got=%lu, want=%lu\n", got, want);
124 main (int argc, char *argv[])