tests/mpq/t-get_d.c failure on m68k-linux

Mikael Pettersson mikpe at it.uu.se
Wed Feb 20 19:34:10 CET 2013


Aldy Hernandez writes:
 > Mikael, can you check this on your setup?  I only have the preprocessed 
 > .i file from the original GCC pr, so I don't have any definitions for 
 > RANDS, MAXEXP, or even gmp_randstate_ptr.
 > 
 > Thanks.
 > Aldy
 > 
 > On 02/19/13 14:25, Niels Möller wrote:
 > 
 > > 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?

This version of check_random makes gmp-5.1.1's test/mpq/t-get_d pass on my
m68k-linux setup.  (It failed to compile in the 5.0.5 I'm currently using
due to MAXEXP being undefined, but looking at 5.1.1 that should be easy to
fix.)

/Mikael

 > >
 > > 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);
 > > }
 > >
 > 


More information about the gmp-bugs mailing list