summaryrefslogtreecommitdiff
path: root/mpz/pprime_p.c
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2002-08-23 09:38:37 +0200
committertege <tege@gmplib.org>2002-08-23 09:38:37 +0200
commit845537a6450ee2d4f64bd4b1e70a26beb9a12168 (patch)
tree0eeec7adb2092ff0ebdeeec2ff47756fb4220ef9 /mpz/pprime_p.c
parent3e9de0bb3cfe86777e6bc720a37cbad626049767 (diff)
downloadgmp-845537a6450ee2d4f64bd4b1e70a26beb9a12168.tar.gz
Partially undo last change--handle small and negative numbers in the
same test.
Diffstat (limited to 'mpz/pprime_p.c')
-rw-r--r--mpz/pprime_p.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/mpz/pprime_p.c b/mpz/pprime_p.c
index 566a090a2..671170fa1 100644
--- a/mpz/pprime_p.c
+++ b/mpz/pprime_p.c
@@ -36,22 +36,21 @@ int
mpz_probab_prime_p (mpz_srcptr n, int reps)
{
mp_limb_t r;
- mpz_t nabs;
-
- if (UNLIKELY (SIZ(n) < 0))
- {
- SIZ(nabs) = - SIZ(n);
- PTR(nabs) = PTR(n);
- ASSERT_CODE (ALLOC(nabs) = ALLOC(n));
- n = nabs;
- }
+ mpz_t n2;
/* Handle small and negative n. */
if (mpz_cmp_ui (n, 1000000L) <= 0)
{
int is_prime;
- is_prime = isprime (mpz_get_ui (n));
- return is_prime ? 2 : 0;
+ if (SIZ(n) >= 0)
+ {
+ is_prime = isprime (mpz_get_ui (n));
+ return is_prime ? 2 : 0;
+ }
+ /* Negative number. Negate and fall out. */
+ PTR(n2) = PTR(n);
+ SIZ(n2) = -SIZ(n);
+ n = n2;
}
/* If n is now even, it is not a prime. */