[Gmp-commit] /var/hg/gmp: 3 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sun Apr 29 23:48:41 UTC 2018
details: /var/hg/gmp/rev/49ddc6327084
changeset: 17615:49ddc6327084
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sat Apr 28 22:42:00 2018 +0200
description:
Improve ASSERTs
details: /var/hg/gmp/rev/2cc2e8efc457
changeset: 17616:2cc2e8efc457
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Mon Apr 30 01:47:28 2018 +0200
description:
mini-gmp/tests/t-mpq_muldiv.c: test mpq_mul (r,a,a)
details: /var/hg/gmp/rev/2bf7fa45600d
changeset: 17617:2bf7fa45600d
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Mon Apr 30 01:48:28 2018 +0200
description:
mini-gmp/mini-mpq.c: special case mpq_mul (r,a,a)
diffstat:
mini-gmp/mini-mpq.c | 35 +++++++++++++++++++----------------
mini-gmp/tests/t-mpq_muldiv.c | 18 +++++++++++++++++-
mpz/bin_ui.c | 3 ++-
tests/mpn/t-toom8h.c | 3 ++-
4 files changed, 40 insertions(+), 19 deletions(-)
diffs (132 lines):
diff -r 27296256af57 -r 2bf7fa45600d mini-gmp/mini-mpq.c
--- a/mini-gmp/mini-mpq.c Sat Apr 28 22:18:19 2018 +0200
+++ b/mini-gmp/mini-mpq.c Mon Apr 30 01:48:28 2018 +0200
@@ -110,15 +110,15 @@
}
static void
-mpq_helper_canonicalize (mpq_t r, const mpq_t c, mpz_t g)
+mpq_helper_canonicalize (mpq_t r, const mpz_t num, const mpz_t den, mpz_t g)
{
- if (mpq_numref (c)->_mp_size == 0)
+ if (num->_mp_size == 0)
mpq_set_ui (r, 0, 1);
else
{
- mpz_gcd (g, mpq_numref (c), mpq_denref (c));
- mpz_tdiv_q (mpq_numref (r), mpq_numref (c), g);
- mpz_tdiv_q (mpq_denref (r), mpq_denref (c), g);
+ mpz_gcd (g, num, den);
+ mpz_tdiv_q (mpq_numref (r), num, g);
+ mpz_tdiv_q (mpq_denref (r), den, g);
mpq_canonical_sign (r);
}
}
@@ -129,7 +129,7 @@
mpz_t t;
mpz_init (t);
- mpq_helper_canonicalize (r, r, t);
+ mpq_helper_canonicalize (r, mpq_numref (r), mpq_denref (r), t);
mpz_clear (t);
}
@@ -342,20 +342,23 @@
void
mpq_mul (mpq_t r, const mpq_t a, const mpq_t b)
{
- mpq_t t, d;
- mpz_t g;
- mpz_init (g);
+ mpq_t t;
mpq_init (t);
- mpq_roinit_z (d, mpq_numref (a), mpq_denref (b));
- mpq_helper_canonicalize (t, d, g);
+ if (a != b) {
+ mpz_t g;
- mpq_roinit_z (d, mpq_numref (b), mpq_denref (a));
- mpq_helper_canonicalize (r, d, g);
- mpz_clear (g);
+ mpz_init (g);
+ mpq_helper_canonicalize (t, mpq_numref (a), mpq_denref (b), g);
+ mpq_helper_canonicalize (r, mpq_numref (b), mpq_denref (a), g);
+ mpz_clear (g);
- mpz_mul (mpq_numref (r), mpq_numref (r), mpq_numref (t));
- mpz_mul (mpq_denref (r), mpq_denref (r), mpq_denref (t));
+ a = r;
+ b = t;
+ }
+
+ mpz_mul (mpq_numref (r), mpq_numref (a), mpq_numref (b));
+ mpz_mul (mpq_denref (r), mpq_denref (a), mpq_denref (b));
mpq_clear (t);
}
diff -r 27296256af57 -r 2bf7fa45600d mini-gmp/tests/t-mpq_muldiv.c
--- a/mini-gmp/tests/t-mpq_muldiv.c Sat Apr 28 22:18:19 2018 +0200
+++ b/mini-gmp/tests/t-mpq_muldiv.c Mon Apr 30 01:48:28 2018 +0200
@@ -52,7 +52,6 @@
unsigned i;
mpz_t an, bn, rn, ad, bd, rd;
mpq_t aq, bq, refq, resq;
- int tst;
mpz_init (an);
mpz_init (bn);
@@ -145,6 +144,23 @@
dump ("resd", mpq_denref (resq));
abort ();
}
+
+ mpq_mul (resq, aq, aq);
+ mpq_mul (refq, aq, bq); /* now bq = - aq */
+ mpq_neg (refq, refq);
+ if (!mpq_equal (resq, refq))
+ {
+ fprintf (stderr, "mpq_mul(sqr) failed [%i]:\n", i);
+ dump ("an", an);
+ dump ("ad", ad);
+ dump ("bn", bn);
+ dump ("bd", bd);
+ dump ("refn", rn);
+ dump ("refd", rd);
+ dump ("resn", mpq_numref (resq));
+ dump ("resd", mpq_denref (resq));
+ abort ();
+ }
}
mpz_clear (an);
diff -r 27296256af57 -r 2bf7fa45600d mpz/bin_ui.c
--- a/mpz/bin_ui.c Sat Apr 28 22:18:19 2018 +0200
+++ b/mpz/bin_ui.c Mon Apr 30 01:48:28 2018 +0200
@@ -105,11 +105,12 @@
/* Computes r = n(n+(2*k-1))/2
It uses a sqare instead of a product, computing
r = ((n+k-1)^2 + n - (k-1)^2)/2
- As a side effect, sets t = n+k
+ As a side effect, sets t = n+k-1
*/
static void
mpz_hmul_nbnpk (mpz_ptr r, mpz_srcptr n, unsigned long int k, mpz_ptr t)
{
+ ASSERT (k > 0 && SIZ(n) > 0);
--k;
mpz_add_ui (t, n, k);
mpz_mul (r, t, t);
diff -r 27296256af57 -r 2bf7fa45600d tests/mpn/t-toom8h.c
--- a/tests/mpn/t-toom8h.c Sat Apr 28 22:18:19 2018 +0200
+++ b/tests/mpn/t-toom8h.c Mon Apr 30 01:48:28 2018 +0200
@@ -8,7 +8,8 @@
#define MIN_AN MUL_TOOM8H_MIN
#define MIN_BN(an) \
-(MAX(GMP_NUMB_BITS <= 10*3 ? (an*6)/10 : \
+(MAX(GMP_NUMB_BITS <= 9*3 ? (an*7)/ 9 : \
+ GMP_NUMB_BITS <= 10*3 ? (an*6)/10 : \
GMP_NUMB_BITS <= 11*3 ? (an*5)/11 : \
GMP_NUMB_BITS <= 12*3 ? (an*4)/12 : \
(an*4)/13, 86) )
More information about the gmp-commit
mailing list