tests/mpq/t-get_d.c failure on m68k-linux
Niels Möller
nisse at lysator.liu.se
Tue Feb 19 21:25:59 CET 2013
nisse at lysator.liu.se (Niels Möller) writes:
> On the other hand, maybe the test ought to be rewritten. Using mpz_get_d
> seems unnecessary.
Below is a rewritten check_random (in tests/mpq/t-get_d.c), with fewer
floating point operations. Works for me (but fails if I increase the
size of A to 54 bits). Can you check if it solves the problem?
Regards,
/Niels
void
check_random (int argc, char **argv)
{
gmp_randstate_ptr rands = RANDS;
double d;
mpq_t q;
mpz_t a, t;
int exp;
int test, reps = 100000;
int i;
if (argc == 2)
reps = 100 * atoi (argv[1]);
mpq_init (q);
mpz_init (a);
mpz_init (t);
for (test = 0; test < reps; test++)
{
mpz_rrandomb (a, rands, 53);
mpz_urandomb (t, rands, 32);
exp = mpz_get_ui (t) % (2*MAXEXP) - MAXEXP;
d = my_ldexp (mpz_get_d (a), exp);
mpq_set_d (q, d);
/* Check that n/d = a * 2^exp, or
d*a 2^{exp} = n */
mpz_mul (t, a, mpq_denref (q));
if (exp > 0)
mpz_mul_2exp (t, t, exp);
else
{
if (!mpz_divisible_2exp_p (t, -exp))
goto fail;
mpz_div_2exp (t, t, -exp);
}
if (mpz_cmp (t, mpq_numref (q)) != 0)
{
fail:
printf ("ERROR (check_random test %d): bad mpq_set_d results\n", test);
printf ("%.16g\n", d);
gmp_printf ("%Qd\n", q);
abort ();
}
}
mpq_clear (q);
mpz_clear (t);
mpz_clear (a);
}
--
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
More information about the gmp-bugs
mailing list