1
/* Tests of mpz_scan0 and mpz_scan1.
3
Copyright 2000, 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 2.1 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; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
MA 02111-1307, USA. */
30
refmpz_scan (mpz_srcptr z, unsigned long i, int sought)
32
unsigned long z_bits = (unsigned long) ABSIZ(z) * BITS_PER_MP_LIMB;
36
if (mpz_tstbit (z, i) == sought)
46
refmpz_scan0 (mpz_srcptr z, unsigned long starting_bit)
48
return refmpz_scan (z, starting_bit, 0);
52
refmpz_scan1 (mpz_srcptr z, unsigned long starting_bit)
54
return refmpz_scan (z, starting_bit, 1);
62
int test, size, neg, sought;
63
unsigned long i, got, want;
66
for (test = 0; test < 10; test++)
68
for (size = 0; size < 5; size++)
70
mpz_random2 (z, size);
72
for (neg = 0; neg <= 1; neg++)
77
for (i = 0; i < size*BITS_PER_MP_LIMB + 8; i++)
79
for (sought = 0; sought <= 1; sought++)
83
got = mpz_scan0 (z, i);
84
want = refmpz_scan0 (z, i);
88
got = mpz_scan1 (z, i);
89
want = refmpz_scan1 (z, i);
94
printf ("wrong at test=%d, size=%d, neg=%d, i=%lu, sought=%d\n",
95
test, size, neg, i, sought);
97
mpz_out_str (stdout, -16, z);
99
printf (" got=%lu, want=%lu\n", got, want);
112
main (int argc, char *argv[])