3 Copyright 2001, 2002 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/. */
30 unsigned long i, j, got, want;
35 for (i = 0; i < 5 * GMP_NUMB_BITS; i++)
37 for (j = 0; j < 5 * GMP_NUMB_BITS; j++)
45 got = mpz_hamdist (x, y);
48 printf ("mpz_hamdist wrong on 2 bits pos/pos\n");
50 printf (" i %lu\n", i);
51 printf (" j %lu\n", j);
52 printf (" got %lu\n", got);
53 printf (" want %lu\n", want);
61 want = ABS ((long) (i-j));
62 got = mpz_hamdist (x, y);
65 printf ("mpz_hamdist wrong on 2 bits neg/neg\n");
79 gmp_randstate_ptr rands = RANDS;
80 unsigned long got, want;
87 for (i = 0; i < 2000; i++)
89 mpz_erandomb (x, rands, 6 * GMP_NUMB_BITS);
90 mpz_negrandom (x, rands);
91 mpz_mul_2exp (x, x, urandom() % (4 * GMP_NUMB_BITS));
93 mpz_erandomb (y, rands, 6 * GMP_NUMB_BITS);
94 mpz_negrandom (y, rands);
95 mpz_mul_2exp (y, y, urandom() % (4 * GMP_NUMB_BITS));
97 want = refmpz_hamdist (x, y);
98 got = mpz_hamdist (x, y);
101 printf ("mpz_hamdist wrong on random\n");
102 printf (" got %lu\n", got);
103 printf (" want %lu\n", want);
104 mpz_trace (" x ", x);
105 mpz_trace (" y ", y);