[Gmp-commit] /var/hg/gmp: tests/devel/primes.c: Support testing composites only.

mercurial at gmplib.org mercurial at gmplib.org
Sat Jan 5 14:43:56 UTC 2019


details:   /var/hg/gmp/rev/036ddbf61ac6
changeset: 17755:036ddbf61ac6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Jan 05 15:43:42 2019 +0100
description:
tests/devel/primes.c: Support testing composites only.

diffstat:

 tests/devel/primes.c |  19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diffs (83 lines):

diff -r 69e6ac05fafe -r 036ddbf61ac6 tests/devel/primes.c
--- a/tests/devel/primes.c	Sat Jan 05 14:17:19 2019 +0100
+++ b/tests/devel/primes.c	Sat Jan 05 15:43:42 2019 +0100
@@ -18,12 +18,14 @@
 
 /* Usage:
 
-   ./primes [p] [n0] <nMax>
+   ./primes [p|c] [n0] <nMax>
 
      Checks mpz_probab_prime_p(n, r) exhaustively, starting from n=n0
      up to nMax.
      If n0 * n0 > nMax, the intervall is sieved piecewise, else the
      full intervall [0..nMax] is sieved at once.
+     With the parameter "p" (or nothing), tests all numbers. With "c"
+     only composites are tested.
 
    ./primes n [n0] <nMax>
 
@@ -106,7 +108,7 @@
 }
 
 int
-check_pprime (unsigned long begin, unsigned long end)
+check_pprime (unsigned long begin, unsigned long end, int composites)
 {
   begin = (begin / 6U) * 6U;
   for (;(begin < 2) & (begin <= end); ++begin)
@@ -120,7 +122,7 @@
     {
       *(g->_mp_d) = begin;
       TRACE(printf ("+%li ", begin),2);
-      if (!mpz_probab_prime_p (g, REPS))
+      if (!composites && !mpz_probab_prime_p (g, REPS))
 	STOP (something_wrong (g, 1));
     }
   if (end > 4) {
@@ -164,7 +166,7 @@
 
 	  *(g->_mp_d) = begin;
 	  TRACE(printf ("+%li ", begin),2);
-	  if (! mpz_probab_prime_p (g, REPS))
+	  if (!composites && ! mpz_probab_prime_p (g, REPS))
 	    STOP (something_wrong (g, 1));
 	  ++begin;
 
@@ -204,7 +206,7 @@
 
 	*(g->_mp_d) = begin;
 	TRACE(printf ("+%li ", begin),2);
-	if (! mpz_probab_prime_p (g, REPS))
+	if (!composites && ! mpz_probab_prime_p (g, REPS))
 	  STOP (something_wrong (g, 1));
 	++begin;
 
@@ -304,6 +306,9 @@
     case 'p':
       mode = 0;
       break;
+    case 'c':
+      mode = 2;
+      break;
     case 'n':
       mode = 1;
       break;
@@ -314,7 +319,7 @@
 
   if (begin >= end)
     {
-      fprintf (stderr, "usage: primes [n|p] [n0] <nMax>\n");
+      fprintf (stderr, "usage: primes [n|p|c] [n0] <nMax>\n");
       exit (1);
     }
 
@@ -325,7 +330,7 @@
     ret = check_nprime (begin, end);
     break;
   default:
-    ret = check_pprime (begin, end);
+    ret = check_pprime (begin, end, mode);
   }
 
   mpz_clear (g);


More information about the gmp-commit mailing list