diff options
| author | Paul Eggert <eggert@cs.ucla.edu> | 2025-07-01 11:48:44 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2025-07-09 17:12:40 -0700 |
| commit | 86bddb0d537442c7c7becad21e9ea320cd4f995b (patch) | |
| tree | b72e99083d3433829ad91298cee2bb7a2d635925 | |
| parent | factor: simplify add_ssaaaa default (diff) | |
| download | coreutils-86bddb0d537442c7c7becad21e9ea320cd4f995b.tar.gz coreutils-86bddb0d537442c7c7becad21e9ea320cd4f995b.zip | |
factor: define SQUARE_OF_FIRST_OMITTED_PRIME
* src/make-prime-list.c (output_primes): Output
SQUARE_OF_FIRST_OMITTED_PRIME, not FIRST_OMITTED_PRIME. All uses
changed. This way, the uses don’t need to worry about casts to
avoid overflow.
| -rw-r--r-- | src/factor.c | 4 | ||||
| -rw-r--r-- | src/make-prime-list.c | 4 |
2 files changed, 3 insertions, 5 deletions
diff --git a/src/factor.c b/src/factor.c index 6fd98bd65..b445dc21a 100644 --- a/src/factor.c +++ b/src/factor.c @@ -1348,7 +1348,7 @@ prime_p (mp_limb_t n) return false; /* We have already cast out small primes. */ - if (n < (mp_limb_t) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) + if (n < SQUARE_OF_FIRST_OMITTED_PRIME) return true; if (USE_BAILLIE_PSW) @@ -1540,7 +1540,7 @@ mp_prime_p (mpz_t n) return false; /* We have already cast out small primes. */ - if (mpz_cmp_ui (n, (long) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) < 0) + if (mpz_cmp_ui (n, SQUARE_OF_FIRST_OMITTED_PRIME) < 0) return true; int probab_prime = mpz_probab_prime_p (n, MR_REPS); diff --git a/src/make-prime-list.c b/src/make-prime-list.c index 7a8e93fc6..2fd10f760 100644 --- a/src/make-prime-list.c +++ b/src/make-prime-list.c @@ -150,8 +150,6 @@ output_primes (const struct prime *primes, unsigned nprimes) p = primes[i].p; } - printf ("\n#undef FIRST_OMITTED_PRIME\n"); - /* Find next prime */ do { @@ -169,7 +167,7 @@ output_primes (const struct prime *primes, unsigned nprimes) } while (!is_prime); - printf ("#define FIRST_OMITTED_PRIME %u\n", p); + printf ("#define SQUARE_OF_FIRST_OMITTED_PRIME %u\n", p * p); } ATTRIBUTE_MALLOC |
