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

mercurial at gmplib.org mercurial at gmplib.org
Fri Jan 18 17:19:37 CET 2013


details:   /var/hg/gmp/rev/5a2c6dd88cfe
changeset: 15300:5a2c6dd88cfe
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Fri Jan 18 17:18:57 2013 +0100
description:
Test also mpz_mod, mpz_mod_ui.  Compare mpz_divisible_p just to ceil, to save time.

details:   /var/hg/gmp/rev/2217098aa833
changeset: 15301:2217098aa833
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Fri Jan 18 17:19:07 2013 +0100
description:
*** empty log message ***

diffstat:

 ChangeLog              |   3 +
 mini-gmp/tests/t-div.c |  76 ++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 65 insertions(+), 14 deletions(-)

diffs (107 lines):

diff -r 67a8a0f7f4ff -r 2217098aa833 ChangeLog
--- a/ChangeLog	Fri Jan 18 16:00:35 2013 +0100
+++ b/ChangeLog	Fri Jan 18 17:19:07 2013 +0100
@@ -1,5 +1,8 @@
 2013-01-18  Torbjorn Granlund  <tege at gmplib.org>
 
+	* mini-gmp/tests/t-div.c: Test also mpz_mod, mpz_mod_ui.  Compare
+	mpz_divisible_p just to ceil, to save time.
+
 	* mini-gmp/mini-gmp.c: Prefix some names with GMP_.
 
 2013-01-18 Marco Bodrato <bodrato at mail.dm.unipi.it>
diff -r 67a8a0f7f4ff -r 2217098aa833 mini-gmp/tests/t-div.c
--- a/mini-gmp/tests/t-div.c	Fri Jan 18 16:00:35 2013 +0100
+++ b/mini-gmp/tests/t-div.c	Fri Jan 18 17:19:07 2013 +0100
@@ -128,14 +128,45 @@
 	      abort ();
 	    }
 
-	  div_p = mpz_divisible_p (a, b);
-	  if ((mpz_sgn (r) == 0) ^ (div_p != 0))
+	  if (j == 0)		/* do this once, not for all roundings */
 	    {
-	      fprintf (stderr, "mpz_divisible_p failed:\n");
-	      dump ("a", a);
-	      dump ("b", b);
-	      dump ("r   ", r);
-	      abort ();
+	      div_p = mpz_divisible_p (a, b);
+	      if ((mpz_sgn (r) == 0) ^ (div_p != 0))
+		{
+		  fprintf (stderr, "mpz_divisible_p failed:\n");
+		  dump ("a", a);
+		  dump ("b", b);
+		  dump ("r   ", r);
+		  abort ();
+		}
+	    }
+
+	  if (j == 0 && mpz_sgn (b) < 0)  /* ceil, negative divisor */
+	    {
+	      mpz_mod (r, a, b);
+	      if (mpz_cmp (r, rr))
+		{
+		  fprintf (stderr, "mpz_mod failed:\n", name[j]);
+		  dump ("a", a);
+		  dump ("b", b);
+		  dump ("r   ", r);
+		  dump ("rref", rr);
+		  abort ();
+		}
+	    }
+
+	  if (j == 1 && mpz_sgn (b) > 0) /* floor, positive divisor */
+	    {
+	      mpz_mod (r, a, b);
+	      if (mpz_cmp (r, rr))
+		{
+		  fprintf (stderr, "mpz_mod failed:\n", name[j]);
+		  dump ("a", a);
+		  dump ("b", b);
+		  dump ("r   ", r);
+		  dump ("rref", rr);
+		  abort ();
+		}
 	    }
 
 	  if (mpz_fits_ulong_p (b))
@@ -195,14 +226,31 @@
 		  abort ();
 		}
 
-	      div_p = mpz_divisible_ui_p (a, mpz_get_ui (b));
-	      if ((mpz_sgn (r) == 0) ^ (div_p != 0))
+	      if (j == 0)	/* do this once, not for all roundings */
 		{
-		  fprintf (stderr, "mpz_divisible_ui_p failed:\n");
-		  dump ("a", a);
-		  dump ("b", b);
-		  dump ("r   ", r);
-		  abort ();
+		  div_p = mpz_divisible_ui_p (a, mpz_get_ui (b));
+		  if ((mpz_sgn (r) == 0) ^ (div_p != 0))
+		    {
+		      fprintf (stderr, "mpz_divisible_ui_p failed:\n");
+		      dump ("a", a);
+		      dump ("b", b);
+		      dump ("r   ", r);
+		      abort ();
+		    }
+		}
+
+	      if (j == 1)	/* floor */
+		{
+		  mpz_mod_ui (r, a, mpz_get_ui (b));
+		  if (mpz_cmp (r, rr))
+		    {
+		      fprintf (stderr, "mpz_mod failed:\n", name[j]);
+		      dump ("a", a);
+		      dump ("b", b);
+		      dump ("r   ", r);
+		      dump ("rref", rr);
+		      abort ();
+		    }
 		}
 	    }
 	}


More information about the gmp-commit mailing list