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

mercurial at gmplib.org mercurial at gmplib.org
Wed Jan 16 17:44:10 CET 2013


details:   /var/hg/gmp/rev/8b6adb3f1d0b
changeset: 15286:8b6adb3f1d0b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 16 17:43:02 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_set_str): Handle the empty string.

details:   /var/hg/gmp/rev/d69baf93e621
changeset: 15287:d69baf93e621
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 16 17:44:04 2013 +0100
description:
mini-gmp/tests/t-str.c: Test base <= 0.

diffstat:

 ChangeLog              |   3 +++
 mini-gmp/mini-gmp.c    |   2 +-
 mini-gmp/tests/t-str.c |  10 +++++-----
 3 files changed, 9 insertions(+), 6 deletions(-)

diffs (67 lines):

diff -r f55a2e396930 -r d69baf93e621 ChangeLog
--- a/ChangeLog	Wed Jan 16 09:49:08 2013 +0100
+++ b/ChangeLog	Wed Jan 16 17:44:04 2013 +0100
@@ -3,6 +3,9 @@
 	* mini-gmp/tests/t-double.c: Test mpz_cmp_d.
 	* mini-gmp/mini-gmp.c (mpz_cmp_d): Correct multiword comparison.
 
+	* mini-gmp/mini-gmp.c (mpz_set_str): Handle the empty string.
+	* mini-gmp/tests/t-str.c: Test base <= 0.
+
 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 f55a2e396930 -r d69baf93e621 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Wed Jan 16 09:49:08 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Wed Jan 16 17:44:04 2013 +0100
@@ -3895,7 +3895,7 @@
     }
 
   sn = strlen (sp);
-  dp = gmp_xalloc (sn);
+  dp = gmp_xalloc (sn + (sn == 0));
 
   for (dn = 0; *sp; sp++)
     {
diff -r f55a2e396930 -r d69baf93e621 mini-gmp/tests/t-str.c
--- a/mini-gmp/tests/t-str.c	Wed Jan 16 09:49:08 2013 +0100
+++ b/mini-gmp/tests/t-str.c	Wed Jan 16 17:44:04 2013 +0100
@@ -58,9 +58,9 @@
   for (i = 0; i < COUNT; i++)
     {
       int base;
-      for (base = 2; base <= 36; base++)
+      for (base = 0; base <= 36; base += 1 + (base == 0))
 	{
-	  hex_random_str_op (MAXBITS, base, &ap, &rp);
+	  hex_random_str_op (MAXBITS, i&1 ? base: -base, &ap, &rp);
 	  if (mpz_set_str (a, ap, 16) != 0)
 	    {
 	      fprintf (stderr, "mpz_set_str failed on input %s\n", ap);
@@ -70,7 +70,7 @@
 	  rn = strlen (rp);
 	  arn = rn - (rp[0] == '-');
 
-	  bn = mpz_sizeinbase (a, base);
+	  bn = mpz_sizeinbase (a, base ? base : 10);
 	  if (bn < arn || bn > (arn + 1))
 	    {
 	      fprintf (stderr, "mpz_sizeinbase failed:\n");
@@ -80,7 +80,7 @@
 		       base, (unsigned) arn, (unsigned)bn);
 	      abort ();
 	    }
-	  bp = mpz_get_str (NULL, base, a);
+	  bp = mpz_get_str (NULL, i&1 ? base: -base, a);
 	  if (strcmp (bp, rp))
 	    {
 	      fprintf (stderr, "mpz_get_str failed:\n");
@@ -106,7 +106,7 @@
 	    }
 	  
 	  /* Test mpn interface */
-	  if (mpz_sgn (a))
+	  if (base && mpz_sgn (a))
 	    {
 	      size_t i;
 	      const char *absr;


More information about the gmp-commit mailing list