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

mercurial at gmplib.org mercurial at gmplib.org
Mon Jan 14 20:10:19 CET 2013


details:   /var/hg/gmp/rev/4df1923c63c9
changeset: 15272:4df1923c63c9
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Mon Jan 14 20:06:58 2013 +0100
description:
Updated copyright year.

details:   /var/hg/gmp/rev/31aa081d3389
changeset: 15273:31aa081d3389
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Mon Jan 14 20:09:13 2013 +0100
description:
mini-gmp: Test mpn_set_str and mpn_get_str.

diffstat:

 ChangeLog                    |   5 +++
 mini-gmp/tests/mini-random.c |   2 +-
 mini-gmp/tests/t-str.c       |  71 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletions(-)

diffs (118 lines):

diff -r 7f31bf56bfe6 -r 31aa081d3389 ChangeLog
--- a/ChangeLog	Mon Jan 14 16:19:42 2013 +0100
+++ b/ChangeLog	Mon Jan 14 20:09:13 2013 +0100
@@ -1,3 +1,8 @@
+2013-01-14  Niels Möller  <nisse at lysator.liu.se>
+
+	* mini-gmp/tests/t-str.c (main): Added tests for mpn_get_str and
+	mpn_set_str.
+
 2013-01-14 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* doc/gmp.texi (gmp_version): Remove "was used" repetition.
diff -r 7f31bf56bfe6 -r 31aa081d3389 mini-gmp/tests/mini-random.c
--- a/mini-gmp/tests/mini-random.c	Mon Jan 14 16:19:42 2013 +0100
+++ b/mini-gmp/tests/mini-random.c	Mon Jan 14 20:09:13 2013 +0100
@@ -1,6 +1,6 @@
 /*
 
-Copyright 2011, Free Software Foundation, Inc.
+Copyright 2011, 2013, Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
diff -r 7f31bf56bfe6 -r 31aa081d3389 mini-gmp/tests/t-str.c
--- a/mini-gmp/tests/t-str.c	Mon Jan 14 16:19:42 2013 +0100
+++ b/mini-gmp/tests/t-str.c	Mon Jan 14 20:09:13 2013 +0100
@@ -18,6 +18,7 @@
 the GNU MP Library test suite.  If not, see http://www.gnu.org/licenses/.  */
 
 #include <assert.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -27,6 +28,9 @@
 #define MAXBITS 400
 #define COUNT 2000
 
+#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
+#define MAXLIMBS ((MAXBITS + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS)
+
 static void
 dump (const char *label, const mpz_t x)
 {
@@ -100,6 +104,73 @@
 	      dump ("r", a);
 	      abort ();
 	    }
+	  
+	  /* Test mpn interface */
+	  if (mpz_sgn (a))
+	    {
+	      size_t i;
+	      const char *absr;
+	      mp_limb_t t[MAXLIMBS];
+	      mp_size_t tn = mpz_size (a);
+
+	      assert (tn <= MAXLIMBS);
+	      mpn_copyi (t, a[0]._mp_d, tn);
+	      
+	      bn = mpn_get_str (bp, base, t, tn);
+	      if (bn != arn)
+		{
+		  fprintf (stderr, "mpn_get_str failed:\n");
+		  fprintf (stderr, "returned length: %d (bad)\n", bn);
+		  fprintf (stderr, "expected: %d\n", arn);
+		  fprintf (stderr, "  base = %d\n", base);
+		  fprintf (stderr, "r = %s\n", ap);
+		  fprintf (stderr, "  base = 16\n");
+		  dump ("b", b);
+		  dump ("r", a);
+		  abort ();
+		}
+	      absr = rp + (rp[0] == '-');
+
+	      for (i = 0; i < bn; i++)
+		{
+		  unsigned char digit = absr[i];
+		  unsigned value;
+		  if (digit >= '0' && digit <= '9')
+		    value = digit - '0';
+		  else if (digit >= 'a' && digit <= 'z')
+		    value = digit - 'a' + 10;
+		  else if (digit >= 'A' && digit <= 'Z')
+		    value = digit - 'A' + 10;
+		  else
+		    {
+		      fprintf (stderr, "Internal error in test.\n");
+		      abort();
+		    }
+		  if (bp[i] != value)
+		    {
+		      fprintf (stderr, "mpn_get_str failed:\n");
+		      fprintf (stderr, "digit %d: %d (bad)\n", i, bp[i]);
+		      fprintf (stderr, "expected: %d\n", value);
+		      fprintf (stderr, "  base = %d\n", base);
+		      fprintf (stderr, "r = %s\n", ap);
+		      fprintf (stderr, "  base = 16\n");
+		      dump ("b", b);
+		      dump ("r", a);
+		      abort ();
+		    }
+		}
+	      tn = mpn_set_str (t, bp, bn, base);
+	      if (tn != mpz_size (a) || mpn_cmp (t, a[0]._mp_d, tn))
+		{
+		  fprintf (stderr, "mpn_set_str failed:\n");
+		  fprintf (stderr, "r = %s\n", rp);
+		  fprintf (stderr, "  base = %d\n", base);
+		  fprintf (stderr, "r = %s\n", ap);
+		  fprintf (stderr, "  base = 16\n");
+		  dump ("r", a);
+		  abort ();
+		}
+	    }
 	  free (ap);
 	  free (bp);
 	}


More information about the gmp-commit mailing list