[Gmp-commit] /var/hg/gmp: 4 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sun Feb 9 07:23:53 UTC 2014
details: /var/hg/gmp/rev/b2dd772a328e
changeset: 16284:b2dd772a328e
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Feb 09 08:14:28 2014 +0100
description:
mini-gmp/tests/t-mul.c: use roinit and limbs_read for mpz<->mpn interaction.
details: /var/hg/gmp/rev/9a732e6858b5
changeset: 16285:9a732e6858b5
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Feb 09 08:15:14 2014 +0100
description:
mini-gmp: add mpn_perfect_square_p, using roinit
details: /var/hg/gmp/rev/1a5a3c9e15ec
changeset: 16286:1a5a3c9e15ec
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Feb 09 08:15:40 2014 +0100
description:
mini-gmp/tests/t-sqrt.c: test also mpn_perfect_square_p
details: /var/hg/gmp/rev/3c807e1d8cbf
changeset: 16287:3c807e1d8cbf
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Feb 09 08:23:38 2014 +0100
description:
ChangeLog
diffstat:
ChangeLog | 14 ++++++++++++--
mini-gmp/mini-gmp.c | 10 ++++++++++
mini-gmp/mini-gmp.h | 1 +
mini-gmp/tests/t-mul.c | 17 +++++++++--------
mini-gmp/tests/t-sqrt.c | 16 +++++++++++-----
5 files changed, 43 insertions(+), 15 deletions(-)
diffs (147 lines):
diff -r aba96e8f2841 -r 3c807e1d8cbf ChangeLog
--- a/ChangeLog Sat Feb 08 18:55:39 2014 +0100
+++ b/ChangeLog Sun Feb 09 08:23:38 2014 +0100
@@ -1,3 +1,13 @@
+2014-02-08 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * mini-gmp/mini-gmp.c (mpz_realloc2, mpz_limbs_read, mpz_limbs_modify
+ mpz_limbs_write, mpz_limbs_finish, mpz_roinit_n): New functions.
+ (mpn_perfect_square_p): New function.
+ * mini-gmp/mini-gmp.h: Declare them.
+
+ * mini-gmp/tests/t-mul.c: Use roinit and limbs_read to test mpn.
+ * mini-gmp/tests/t-sqrt.c: Test also mpn_perfect_square_p.
+
2014-02-08 Niels Möller <nisse at lysator.liu.se>
* mpn/generic/sec_invert.c (mpn_cnd_neg_itch): #if:ed out unused
@@ -21,8 +31,8 @@
(mpz_perfect_square_p): New function.
* mini-gmp/mini-gmp.h: Declare them.
- * mini-gmp/tests/t-sqrt.c: test mpz_perfect_square_p
- * mini-gmp/tests/t-root.c: test also 1-th root, allow perfect powers.
+ * mini-gmp/tests/t-sqrt.c: Test mpz_perfect_square_p.
+ * mini-gmp/tests/t-root.c: Test also 1-th root, allow perfect powers.
2014-01-29 Torbjorn Granlund <tege at gmplib.org>
diff -r aba96e8f2841 -r 3c807e1d8cbf mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Sat Feb 08 18:55:39 2014 +0100
+++ b/mini-gmp/mini-gmp.c Sun Feb 09 08:23:38 2014 +0100
@@ -3276,6 +3276,16 @@
else
return mpz_root (NULL, u, 2);
}
+
+int
+mpn_perfect_square_p (mp_srcptr p, mp_size_t n)
+{
+ mpz_t t;
+
+ assert (n > 0);
+ assert (p [n-1] != 0);
+ return mpz_root (NULL, mpz_roinit_n (t, p, n), 2);
+}
/* Combinatorics */
diff -r aba96e8f2841 -r 3c807e1d8cbf mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h Sat Feb 08 18:55:39 2014 +0100
+++ b/mini-gmp/mini-gmp.h Sun Feb 09 08:23:38 2014 +0100
@@ -98,6 +98,7 @@
mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t);
+int mpn_perfect_square_p (mp_srcptr, mp_size_t);
mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);
mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);
diff -r aba96e8f2841 -r 3c807e1d8cbf mini-gmp/tests/t-mul.c
--- a/mini-gmp/tests/t-mul.c Sat Feb 08 18:55:39 2014 +0100
+++ b/mini-gmp/tests/t-mul.c Sun Feb 09 08:23:38 2014 +0100
@@ -1,6 +1,6 @@
/*
-Copyright 2012, Free Software Foundation, Inc.
+Copyright 2012, 2014, Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
@@ -42,9 +42,9 @@
testmain (int argc, char **argv)
{
unsigned i;
- mpz_t a, b, res, res_ui, ref;
+ mpz_t a, b, res, res_ui, ref, tz;
mp_limb_t t[2*MAXLIMBS];
- mp_size_t an, rn;
+ mp_size_t an;
mpz_init (a);
mpz_init (b);
@@ -72,8 +72,9 @@
if (an > 0)
{
mpn_mul_n (t, a->_mp_d, b->_mp_d, an);
- rn = 2*an - (t[2*an-1] == 0);
- if (rn != mpz_size (ref) || mpn_cmp (t, ref->_mp_d, rn))
+
+ mpz_roinit_n (tz, t, 2*an);
+ if (mpz_cmpabs (tz, ref))
{
fprintf (stderr, "mpn_mul_n failed:\n");
dump ("a", a);
@@ -100,10 +101,10 @@
if (an > 0)
{
memset (t, 0x33, sizeof(t));
- mpn_sqr (t, a->_mp_d, an);
+ mpn_sqr (t, mpz_limbs_read (a), an);
- rn = 2*an - (t[2*an-1] == 0);
- if (rn != mpz_size (ref) || mpn_cmp (t, ref->_mp_d, rn))
+ mpz_roinit_n (tz, t, 2*an);
+ if (mpz_cmp (tz, ref))
{
fprintf (stderr, "mpn (squaring) failed:\n");
dump ("a", a);
diff -r aba96e8f2841 -r 3c807e1d8cbf mini-gmp/tests/t-sqrt.c
--- a/mini-gmp/tests/t-sqrt.c Sat Feb 08 18:55:39 2014 +0100
+++ b/mini-gmp/tests/t-sqrt.c Sun Feb 09 08:23:38 2014 +0100
@@ -1,6 +1,6 @@
/*
-Copyright 2012, Free Software Foundation, Inc.
+Copyright 2012, 2014, Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
@@ -103,17 +103,23 @@
mpz_sub_ui (u, u, 1);
}
- if (mpz_perfect_square_p (u))
+ if ((mpz_sgn (u) <= 0 || (i & 1)) ?
+ mpz_perfect_square_p (u) :
+ mpn_perfect_square_p (mpz_limbs_read (u), mpz_size (u)))
{
- fprintf (stderr, "mpz_perfect_square_p failed on non square:\n");
+ fprintf (stderr, "mp%s_perfect_square_p failed on non square:\n",
+ (mpz_sgn (u) <= 0 || (i & 1)) ? "z" : "n");
dump ("u", u);
abort ();
}
mpz_mul (u, s, s);
- if (!mpz_perfect_square_p (u))
+ if (!((mpz_sgn (u) <= 0 || (i & 1)) ?
+ mpz_perfect_square_p (u) :
+ mpn_perfect_square_p (mpz_limbs_read (u), mpz_size (u))))
{
- fprintf (stderr, "mpz_perfect_square_p failed on square:\n");
+ fprintf (stderr, "mp%s_perfect_square_p failed on square:\n",
+ (mpz_sgn (u) <= 0 || (i & 1)) ? "z" : "n");
dump ("u", u);
abort ();
}
More information about the gmp-commit
mailing list