[Gmp-commit] /var/hg/gmp-5.0: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Mon Nov 12 20:25:29 CET 2012
details: /var/hg/gmp-5.0/rev/cd26bbad239e
changeset: 13586:cd26bbad239e
user: Torbjorn Granlund <tege at gmplib.org>
date: Mon Nov 12 20:22:05 2012 +0100
description:
Remove test for old GMP release.
details: /var/hg/gmp-5.0/rev/e50aa4d72823
changeset: 13587:e50aa4d72823
user: Torbjorn Granlund <tege at gmplib.org>
date: Mon Nov 12 20:25:27 2012 +0100
description:
Fix mpq mord_2exp bug, enhance related testing.
diffstat:
ChangeLog | 5 +++
mpn/generic/trialdiv.c | 7 +----
mpq/md_2exp.c | 4 +-
tests/mpq/t-md_2exp.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 72 insertions(+), 9 deletions(-)
diffs (127 lines):
diff -r 829215e83ff1 -r e50aa4d72823 ChangeLog
--- a/ChangeLog Sat Jul 21 19:19:11 2012 +0200
+++ b/ChangeLog Mon Nov 12 20:25:27 2012 +0100
@@ -1,3 +1,8 @@
+2012-11-12 Torbjorn Granlund <tege at gmplib.org>
+
+ * mpq/md_2exp.c: Use MPN_COPY_INCR, not MPN_COPY_DECR.
+ * tests/mpq/t-md_2exp.c (check_random): New function.
+
2012-07-21 Torbjorn Granlund <tege at gmplib.org>
* mpn/powerpc32/vmx/mod_34lsub1.asm: Fix r0 clobbering issue with
diff -r 829215e83ff1 -r e50aa4d72823 mpn/generic/trialdiv.c
--- a/mpn/generic/trialdiv.c Sat Jul 21 19:19:11 2012 +0200
+++ b/mpn/generic/trialdiv.c Mon Nov 12 20:25:27 2012 +0100
@@ -80,12 +80,7 @@
ppp = gmp_primes_ptab[i].ppp;
cps = gmp_primes_ptab[i].cps;
-#if __GNU_MP_VERSION == 4 && __GNU_MP_VERSION_MINOR < 4
- if (tn < 4)
- r = mpn_mod_1 (tp, tn, ppp); /* FIXME */
- else
-#endif
- r = mpn_mod_1s_4p (tp, tn, ppp << cps[1], cps);
+ r = mpn_mod_1s_4p (tp, tn, ppp << cps[1], cps);
idx = gmp_primes_ptab[i].idx;
np = gmp_primes_ptab[i].np;
diff -r 829215e83ff1 -r e50aa4d72823 mpq/md_2exp.c
--- a/mpq/md_2exp.c Sat Jul 21 19:19:11 2012 +0200
+++ b/mpq/md_2exp.c Mon Nov 12 20:25:27 2012 +0100
@@ -53,9 +53,9 @@
if ((plow & 1) || n == 0)
{
- /* need DECR when src==dst */
+ /* need INCR when src==dst */
if (p != rdst_ptr)
- MPN_COPY_DECR (rdst_ptr, p, len);
+ MPN_COPY_INCR (rdst_ptr, p, len);
}
else
{
diff -r 829215e83ff1 -r e50aa4d72823 tests/mpq/t-md_2exp.c
--- a/tests/mpq/t-md_2exp.c Sat Jul 21 19:19:11 2012 +0200
+++ b/tests/mpq/t-md_2exp.c Mon Nov 12 20:25:27 2012 +0100
@@ -29,8 +29,69 @@
const char *den;
};
+void
+check_random ()
+{
+ gmp_randstate_ptr rands;
+ mpz_t bs;
+ unsigned long arg_size, size_range;
+ mpq_t q, r;
+ int i;
+ mp_bitcnt_t shift;
+ int reps = 10000;
+
+ rands = RANDS;
+
+ mpz_init (bs);
+ mpq_init (q);
+ mpq_init (r);
+
+ for (i = 0; i < reps; i++)
+ {
+ mpz_urandomb (bs, rands, 32);
+ size_range = mpz_get_ui (bs) % 11 + 2; /* 0..4096 bit operands */
+
+ mpz_urandomb (bs, rands, size_range);
+ arg_size = mpz_get_ui (bs);
+ mpz_rrandomb (mpq_numref (q), rands, arg_size);
+ do
+ {
+ mpz_urandomb (bs, rands, size_range);
+ arg_size = mpz_get_ui (bs);
+ mpz_rrandomb (mpq_denref (q), rands, arg_size);
+ }
+ while (mpz_sgn (mpq_denref (q)) == 0);
+
+ /* We now have a random rational in q, albeit an unnormalised one. The
+ lack of normalisation should not matter here, so let's save the time a
+ gcd would require. */
+
+ mpz_urandomb (bs, rands, 32);
+ shift = mpz_get_ui (bs) % 4096;
+
+ mpq_mul_2exp (r, q, shift);
+
+ if (mpq_cmp (r, q) < 0)
+ {
+ printf ("mpq_mul_2exp wrong on random\n");
+ abort ();
+ }
+
+ mpq_div_2exp (r, r, shift);
+
+ if (mpq_cmp (r, q) != 0)
+ {
+ printf ("mpq_mul_2exp or mpq_div_2exp wrong on random\n");
+ abort ();
+ }
+ }
+ mpq_clear (q);
+ mpq_clear (r);
+ mpz_clear (bs);
+}
+
int
-main (void)
+main (int argc, char **argv)
{
static const struct {
struct pair_t left;
@@ -173,6 +234,8 @@
}
}
+ check_random ();
+
mpq_clear (sep);
mpq_clear (got);
mpq_clear (want);
More information about the gmp-commit
mailing list