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

mercurial at gmplib.org mercurial at gmplib.org
Thu Jan 23 20:17:52 UTC 2014


details:   /var/hg/gmp/rev/2fdc95b4aafb
changeset: 16247:2fdc95b4aafb
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jan 23 21:15:35 2014 +0100
description:
mini-gmp/tests/t-aorsmul.c: New file, test for mpz_{add,sub}mul{,_ui}

details:   /var/hg/gmp/rev/f094e95ba52d
changeset: 16248:f094e95ba52d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jan 23 21:16:53 2014 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/6b3e031bcd37
changeset: 16249:6b3e031bcd37
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jan 23 21:17:43 2014 +0100
description:
Copyright year

diffstat:

 ChangeLog                  |   3 +
 mini-gmp/tests/Makefile    |   4 +-
 mini-gmp/tests/t-aorsmul.c |  85 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 2 deletions(-)

diffs (122 lines):

diff -r b5d44ad58f49 -r 6b3e031bcd37 ChangeLog
--- a/ChangeLog	Thu Jan 23 18:37:27 2014 +0100
+++ b/ChangeLog	Thu Jan 23 21:17:43 2014 +0100
@@ -3,6 +3,9 @@
 	* printf/repl-vsnprintf.c: Feed case 'z' in switch (type) with case 'z'
 	in switch (fchar).
 
+	* mini-gmp/tests/t-aorsmul.c: New file, test for mpz_{add,sub}mul{,_ui}
+	* mini-gmp/tests/Makefile: Add t-aorsmul.
+
 2014-01-21 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* acinclude.m4 (GMP_FUNC_VSNPRINTF): Get rid of varargs.
diff -r b5d44ad58f49 -r 6b3e031bcd37 mini-gmp/tests/Makefile
--- a/mini-gmp/tests/Makefile	Thu Jan 23 18:37:27 2014 +0100
+++ b/mini-gmp/tests/Makefile	Thu Jan 23 21:17:43 2014 +0100
@@ -1,6 +1,6 @@
 # Note: Requires GNU make
 
-# Copyright 2011, 2012 Free Software Foundation, Inc.
+# Copyright 2011, 2012, 2014 Free Software Foundation, Inc.
 #
 # This file is part of the GNU MP Library test suite.
 #
@@ -30,7 +30,7 @@
 CHECK_PROGRAMS = t-add t-sub t-mul t-invert t-div t-div_2exp \
 	t-double t-cmp_d t-gcd t-lcm t-import t-comb t-signed \
 	t-sqrt t-root t-powm t-logops t-bitops t-scan t-str \
-	t-reuse
+	t-reuse t-aorsmul
 
 MISC_OBJS = hex-random.o mini-random.o testutils.o
 
diff -r b5d44ad58f49 -r 6b3e031bcd37 mini-gmp/tests/t-aorsmul.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mini-gmp/tests/t-aorsmul.c	Thu Jan 23 21:17:43 2014 +0100
@@ -0,0 +1,85 @@
+/*
+
+Copyright 2012, 2014, Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library test suite.
+
+The GNU MP Library test suite is free software; you can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 3 of the License,
+or (at your option) any later version.
+
+The GNU MP Library test suite is distributed in the hope that it will be
+useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
+
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "testutils.h"
+
+#define MAXBITS 400
+#define COUNT 10000
+
+#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)
+{
+  char *buf = mpz_get_str (NULL, 16, x);
+  fprintf (stderr, "%s: %s\n", label, buf);
+  testfree (buf);
+}
+
+void
+testmain (int argc, char **argv)
+{
+  unsigned i;
+  mpz_t a, b, res, ref;
+
+  mpz_init (a);
+  mpz_init (b);
+  mpz_init_set_ui (res, 5);
+  mpz_init (ref);
+
+  for (i = 0; i < COUNT; i++)
+    {
+      mini_random_op3 (OP_MUL, MAXBITS, a, b, ref);
+      if (i & 1) {
+	mpz_add (ref, ref, res);
+	if (mpz_fits_ulong_p (b))
+	  mpz_addmul_ui (res, a, mpz_get_ui (b));
+	else
+	  mpz_addmul (res, a, b);
+      } else {
+	mpz_sub (ref, res, ref);
+	if (mpz_fits_ulong_p (b))
+	  mpz_submul_ui (res, a, mpz_get_ui (b));
+	else
+	  mpz_submul (res, a, b);
+      }
+      if (mpz_cmp (res, ref))
+	{
+	  if (i & 1)
+	    fprintf (stderr, "mpz_addmul failed:\n");
+	  else
+	    fprintf (stderr, "mpz_submul failed:\n");
+	  dump ("a", a);
+	  dump ("b", b);
+	  dump ("r", res);
+	  dump ("ref", ref);
+	  abort ();
+	}
+    }
+  mpz_clear (a);
+  mpz_clear (b);
+  mpz_clear (res);
+  mpz_clear (ref);
+}


More information about the gmp-commit mailing list