]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
factor: define SQUARE_OF_FIRST_OMITTED_PRIME
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 1 Jul 2025 18:48:44 +0000 (11:48 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 10 Jul 2025 00:12:40 +0000 (17:12 -0700)
* 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.

src/factor.c
src/make-prime-list.c

index 6fd98bd65b192e7a4f104ce08a156e2bc4c40ee4..b445dc21a502e40af2c92478e5ea87f39968b158 100644 (file)
@@ -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);
index 7a8e93fc67a6b9ab4b83f213d1d74914b7dbdf7c..2fd10f760c31af48c857de4fbd677aefd59b9e21 100644 (file)
@@ -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