3 Copyright 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/. */
28 check_one (mpz_srcptr z)
30 static const int shift[] = {
31 0, 1, GMP_LIMB_BITS, 2*GMP_LIMB_BITS, 5*GMP_LIMB_BITS
38 mpf_init2 (f, mpz_sizeinbase(z,2));
42 for (sh = 0; sh < numberof(shift); sh++)
44 for (shneg = 0; shneg <= 1; shneg++)
46 for (neg = 0; neg <= 1; neg++)
59 mpz_tdiv_q_2exp (want, want, shift[sh]);
60 mpf_div_2exp (f, f, shift[sh]);
64 mpz_mul_2exp (want, want, shift[sh]);
65 mpf_mul_2exp (f, f, shift[sh]);
69 MPZ_CHECK_FORMAT (got);
71 if (mpz_cmp (got, want) != 0)
73 printf ("wrong result\n");
74 printf (" shift %d\n", shneg ? -shift[sh] : shift[sh]);
75 printf (" neg %d\n", neg);
77 mpz_trace (" got", got);
78 mpz_trace (" want", want);
101 mpz_set_si (z, 123L);
104 mpz_rrandomb (z, RANDS, 2*GMP_LIMB_BITS);
107 mpz_rrandomb (z, RANDS, 5*GMP_LIMB_BITS);
115 main (int argc, char *argv[])
117 #if GMP_NAIL_BITS == 0