3 Copyright 2009 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 #define SZ (2 * sizeof(mp_limb_t))
29 void insert_random_low_zero_limbs (mpf_t, gmp_randstate_ptr);
30 void dump_abort (mpf_t, mpf_t, int, int, int, int, int, long);
34 main (int argc, char **argv)
36 unsigned long test, reps = 10000;
38 gmp_randstate_ptr rands;
40 int hibits, lshift1, lshift2;
48 reps = strtol (argv[1], 0, 0);
54 mpf_set_default_prec ((1 << HIBITS) + (1 << LSHIFT1) + (1 << LSHIFT2));
57 mpf_inits (a, b, x, NULL);
59 for (test = 0; test < reps; test++)
61 mpz_urandomb (ds, rands, HIBITS);
62 hibits = mpz_get_ui (ds) + 1;
63 mpz_urandomb (ds, rands, hibits);
64 mpz_setbit (ds, hibits - 1); /* make sure msb is set */
68 mpz_urandomb (ds, rands, LSHIFT1);
69 lshift1 = mpz_get_ui (ds);
70 mpf_mul_2exp (a, a, lshift1 + 1);
71 mpf_mul_2exp (b, b, lshift1 + 1);
72 mpf_add_ui (a, a, 1); /* make a one-bit difference */
74 mpz_urandomb (ds, rands, LSHIFT2);
75 lshift2 = mpz_get_ui (ds);
76 mpf_mul_2exp (a, a, lshift2);
77 mpf_mul_2exp (b, b, lshift2);
78 mpz_urandomb (ds, rands, lshift2);
83 insert_random_low_zero_limbs (a, rands);
84 insert_random_low_zero_limbs (b, rands);
86 if (mpf_eq (a, b, lshift1 + hibits) == 0)
88 dump_abort (a, b, lshift1 + hibits, lshift1, lshift2, hibits, 1, test);
90 for (xtra = 1; xtra < 100; xtra++)
91 if (mpf_eq (a, b, lshift1 + hibits + xtra) != 0)
93 dump_abort (a, b, lshift1 + hibits + xtra, lshift1, lshift2, hibits, 0, test);
97 mpf_clears (a, b, x, NULL);
104 insert_random_low_zero_limbs (mpf_t x, gmp_randstate_ptr rands)
106 mp_size_t max = PREC(x) - SIZ(x);
108 mpz_t ds; mpz_init (ds);
109 mpz_urandomb (ds, rands, 32);
110 s = mpz_get_ui (ds) % (max + 1);
111 MPN_COPY_DECR (PTR(x) + s, PTR(x), SIZ(x));
112 MPN_ZERO (PTR(x), s);
118 dump_abort (mpf_t a, mpf_t b, int cmp_prec, int lshift1, int lshift2, int hibits, int want, long test)
120 printf ("ERROR in test %ld\n", test);
121 printf ("want %d got %d from mpf_eq\n", want, 1-want);
122 printf ("cmp_prec = %d\n", cmp_prec);
123 printf ("lshift1 = %d\n", lshift1);
124 printf ("lshift2 = %d\n", lshift2);
125 printf ("hibits = %d\n", hibits);
126 hexdump (a); puts ("");
127 hexdump (b); puts ("");
135 for (i = ABSIZ(x) - 1; i >= 0; i--)
137 gmp_printf ("%0*MX", SZ, PTR(x)[i]);