diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2019-01-05 15:43:42 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2019-01-05 15:43:42 +0100 |
commit | aea95ff085c50560712cb330edf49a6a349f86ac (patch) | |
tree | c30f171611f158a49d7a1ba39690c4882a52598a /tests/devel | |
parent | fb05bd4f3ccadad1a0a5b90f6daf9db2902c6a7c (diff) | |
download | gmp-aea95ff085c50560712cb330edf49a6a349f86ac.tar.gz |
tests/devel/primes.c: Support testing composites only.
Diffstat (limited to 'tests/devel')
-rw-r--r-- | tests/devel/primes.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/devel/primes.c b/tests/devel/primes.c index 861da9151..84b3b5117 100644 --- a/tests/devel/primes.c +++ b/tests/devel/primes.c @@ -18,12 +18,14 @@ the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ /* 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 something_wrong (mpz_t er, int exp) } 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 @@ check_pprime (unsigned long begin, unsigned long end) { *(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 @@ check_pprime (unsigned long begin, unsigned long end) *(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 @@ check_pprime (unsigned long begin, unsigned long end) *(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 @@ main (int argc, char **argv) case 'p': mode = 0; break; + case 'c': + mode = 2; + break; case 'n': mode = 1; break; @@ -314,7 +319,7 @@ main (int argc, char **argv) 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 @@ main (int argc, char **argv) ret = check_nprime (begin, end); break; default: - ret = check_pprime (begin, end); + ret = check_pprime (begin, end, mode); } mpz_clear (g); |