[Gmp-commit] /var/hg/gmp: 4 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Wed Jan 16 09:49:38 CET 2013


details:   /var/hg/gmp/rev/722607d78936
changeset: 15282:722607d78936
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 16 09:46:28 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_cmp_d): Correct multiword comparisons

details:   /var/hg/gmp/rev/8800d6c383cd
changeset: 15283:8800d6c383cd
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 16 09:47:34 2013 +0100
description:
mini-gmp/tests/t-double.c: don't repeat code.

details:   /var/hg/gmp/rev/381f4cc7d5c5
changeset: 15284:381f4cc7d5c5
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 16 09:48:17 2013 +0100
description:
mini-gmp/tests/t-double.c: Test mpz_cmp_d.

details:   /var/hg/gmp/rev/f55a2e396930
changeset: 15285:f55a2e396930
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 16 09:49:08 2013 +0100
description:
Comments.

diffstat:

 ChangeLog                 |   5 +++++
 mini-gmp/mini-gmp.c       |   4 ++--
 mini-gmp/tests/t-double.c |  37 ++++++++++++++++++++++++++++---------
 mini-gmp/tests/t-signed.c |   6 +++---
 4 files changed, 38 insertions(+), 14 deletions(-)

diffs (129 lines):

diff -r 02e38b8208d8 -r f55a2e396930 ChangeLog
--- a/ChangeLog	Tue Jan 15 22:44:27 2013 +0100
+++ b/ChangeLog	Wed Jan 16 09:49:08 2013 +0100
@@ -1,3 +1,8 @@
+2013-01-16 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mini-gmp/tests/t-double.c: Test mpz_cmp_d.
+	* mini-gmp/mini-gmp.c (mpz_cmp_d): Correct multiword comparison.
+
 2013-01-15  Niels Möller  <nisse at lysator.liu.se>
 
 	* mini-gmp/tests/t-str.c (main): Use x->_mp_d rather than x[0]._mp_d.
diff -r 02e38b8208d8 -r f55a2e396930 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Tue Jan 15 22:44:27 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Wed Jan 16 09:49:08 2013 +0100
@@ -1585,7 +1585,7 @@
   if (d >= B)
     return -sign;
 
-  for (i = xn; i-- > 0; i++)
+  for (i = xn; i-- > 0; i)
     {
       mp_limb_t f, xl;
 
@@ -1605,7 +1605,7 @@
 }
 
 
-/* MPN comparisons and the like. */
+/* MPZ comparisons and the like. */
 int
 mpz_sgn (const mpz_t u)
 {
diff -r 02e38b8208d8 -r f55a2e396930 mini-gmp/tests/t-double.c
--- a/mini-gmp/tests/t-double.c	Tue Jan 15 22:44:27 2013 +0100
+++ b/mini-gmp/tests/t-double.c	Wed Jan 16 09:49:08 2013 +0100
@@ -1,6 +1,6 @@
 /*
 
-Copyright 2012, Free Software Foundation, Inc.
+Copyright 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
@@ -99,13 +99,20 @@
       if (f != floor (d))
 	{
 	  fprintf (stderr, "mpz_set_d/mpz_get_d failed:\n");
-	  dump ("x", x);
-	  fprintf (stderr, "m = %lx, e = %i\n", m, e);
-	  fprintf (stderr, "d = %.15g\n", d);
-	  fprintf (stderr, "f = %.15g\n", f);
-	  fprintf (stderr, "d - f = %.5g\n", d - f);
-	  abort ();
+	  goto dumperror;
 	}
+      if ((f == d) ? (mpz_cmp_d (x, d) != 0) : (mpz_cmp_d (x, d) >= 0))
+	{
+	  fprintf (stderr, "mpz_cmp_d (x, d) failed:\n");
+	  goto dumperror;
+	}
+      f = d + 1;
+      if (f > d && ! (mpz_cmp_d (x, f) < 0))
+	{
+	  fprintf (stderr, "mpz_cmp_d (x, f) failed:\n");
+	  goto dumperror;
+	}
+
       d = - d;
 
       mpz_set_d (x, d);
@@ -113,13 +120,25 @@
       if (f != ceil (d))
 	{
 	  fprintf (stderr, "mpz_set_d/mpz_get_d failed:\n");
+	dumperror:
 	  dump ("x", x);
 	  fprintf (stderr, "m = %lx, e = %i\n", m, e);
 	  fprintf (stderr, "d = %.15g\n", d);
-	  fprintf (stderr, "c = %.15g\n", f);
-	  fprintf (stderr, "c - d = %.5g\n", f - d);
+	  fprintf (stderr, "f = %.15g\n", f);
+	  fprintf (stderr, "f - d = %.5g\n", f - d);
 	  abort ();
 	}
+      if ((f == d) ? (mpz_cmp_d (x, d) != 0) : (mpz_cmp_d (x, d) <= 0))
+	{
+	  fprintf (stderr, "mpz_cmp_d (x, d) failed:\n");
+	  goto dumperror;
+	}
+      f = d - 1;
+      if (f < d && ! (mpz_cmp_d (x, f) > 0))
+	{
+	  fprintf (stderr, "mpz_cmp_d (x, f) failed:\n");
+	  goto dumperror;
+	}
     }
 
   mpz_clear (x);
diff -r 02e38b8208d8 -r f55a2e396930 mini-gmp/tests/t-signed.c
--- a/mini-gmp/tests/t-signed.c	Tue Jan 15 22:44:27 2013 +0100
+++ b/mini-gmp/tests/t-signed.c	Wed Jan 16 09:49:08 2013 +0100
@@ -69,7 +69,7 @@
   mpz_init_set (oz, sz);
 
   do {
-    si *= 2;
+    si *= 2; /* c * 2^k */
     mpz_mul_2exp (sz, sz, 1);
 
     if (mpz_cmp_si (sz, oi) != c)
@@ -87,7 +87,7 @@
 
     check_si (sz, oz, si, c);
 
-    oi = si + c;
+    oi = si + c; /* c * (2^k + 1) */
     if (c == -1)
       mpz_sub_ui (oz, sz, 1);
     else
@@ -105,7 +105,7 @@
 
     check_si (oz, sz, oi, c);
 
-    oi = (si - c) * 2 + c;
+    oi = (si - c) * 2 + c; /* c * (2^K - 1) */
     mpz_mul_si (oz, sz, 2*c); 
     if (c == -1)
       mpz_ui_sub (oz, 1, oz); /* oz = sz * 2 + 1 */


More information about the gmp-commit mailing list