diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2015-12-11 08:13:46 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2015-12-11 08:13:46 +0100 |
commit | 8cc469eedced3127bccfa802c83e9a890af7446e (patch) | |
tree | d7c5a244c60f49649368c89cbada69af531157d8 /mpz/pprime_p.c | |
parent | ac8718e7ee89006e7cf928af8728ed9252b95b5e (diff) | |
download | gmp-8cc469eedced3127bccfa802c83e9a890af7446e.tar.gz |
mpz/pprime_p.c: Check for parity where it is needed only.
Diffstat (limited to 'mpz/pprime_p.c')
-rw-r--r-- | mpz/pprime_p.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/mpz/pprime_p.c b/mpz/pprime_p.c index f3d38a082..bfa1b8fda 100644 --- a/mpz/pprime_p.c +++ b/mpz/pprime_p.c @@ -6,7 +6,8 @@ positive is (1/4)**reps, where reps is the number of internal passes of the probabilistic algorithm. Knuth indicates that 25 passes are reasonable. -Copyright 1991, 1993, 1994, 1996-2002, 2005 Free Software Foundation, Inc. +Copyright 1991, 1993, 1994, 1996-2002, 2005, 2015 Free Software +Foundation, Inc. This file is part of the GNU MP Library. @@ -55,10 +56,12 @@ mpz_probab_prime_p (mpz_srcptr n, int reps) /* Handle small and negative n. */ if (mpz_cmp_ui (n, 1000000L) <= 0) { - int is_prime; if (mpz_cmpabs_ui (n, 1000000L) <= 0) { - is_prime = isprime (mpz_get_ui (n)); + int is_prime; + unsigned long n0; + n0 = mpz_get_ui (n); + is_prime = n0 & (n0 > 1) ? isprime (n0) : n0 == 2; return is_prime ? 2 : 0; } /* Negative number. Negate and fall out. */ @@ -68,7 +71,7 @@ mpz_probab_prime_p (mpz_srcptr n, int reps) } /* If n is now even, it is not a prime. */ - if ((mpz_get_ui (n) & 1) == 0) + if (mpz_even_p (n)) return 0; #if defined (PP) @@ -150,8 +153,7 @@ isprime (unsigned long int t) { unsigned long int q, r, d; - if (t < 3 || (t & 1) == 0) - return t == 2; + ASSERT (t >= 3 && (t & 1) != 0); for (d = 3, r = 1; r != 0; d += 2) { |