bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12350: Composites identified as primes in factor.c (when HAVE_GMP)


From: Pádraig Brady
Subject: bug#12350: Composites identified as primes in factor.c (when HAVE_GMP)
Date: Mon, 08 Oct 2012 11:37:45 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 10/07/2012 10:00 AM, Jim Meyering wrote:
Torbjorn Granlund wrote:
Jim Meyering <address@hidden> writes:

   How about this in place of the final sentence?

                                                       The new program also
       runs a deterministic primality test for each prime factor, not just
       a probabilistic test.

That's better, thanks.

I pushed the actual bug fix (for the issue mentioned in the Subject)
long ago, so I'm closing this "issue".

Regarding your upcoming improvements, please start a new thread
when you're ready to discuss them, so that your comments are not
lost in the volume of with this now-"done" bug report.

A small amendment I'm going to push is not to rely on GMP5.
GMP4 on my fedora 15 system doesn't have mpz_inits().
i.e. support for initializing multiple variables at once.

Patch is simple enough...

diff --git a/src/factor.c b/src/factor.c
index 5bfbfdc..1857297 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -1335,7 +1335,10 @@ mp_prime_p (mpz_t n)
   if (mpz_cmp_ui (n, (long) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) < 0)
     return true;

-  mpz_inits (q, a, nm1, tmp, NULL);
+  mpz_init (q);
+  mpz_init (a);
+  mpz_init (nm1);
+  mpz_init (tmp);

   /* Precomputation for Miller-Rabin.  */
   mpz_sub_ui (nm1, n, 1);
@@ -1399,7 +1402,10 @@ mp_prime_p (mpz_t n)
   if (flag_prove_primality)
     mp_factor_clear (&factors);
  ret2:
-  mpz_clears (q, a, nm1, tmp, NULL);
+  mpz_clear (q);
+  mpz_clear (a);
+  mpz_clear (nm1);
+  mpz_clear (tmp);

   return is_prime;
 }
@@ -1608,7 +1614,8 @@ mp_factor_using_pollard_rho (mpz_t n, unsigned long int a,

   debug ("[pollard-rho (%lu)] ", a);

-  mpz_inits (t, t2, NULL);
+  mpz_init (t);
+  mpz_init (t2);
   mpz_init_set_si (y, 2);
   mpz_init_set_si (x, 2);
   mpz_init_set_si (z, 2);
@@ -1688,7 +1695,12 @@ mp_factor_using_pollard_rho (mpz_t n, unsigned long int 
a,
       mpz_mod (y, y, n);
     }

-  mpz_clears (P, t2, t, z, x, y, NULL);
+  mpz_clear (P);
+  mpz_clear (t2);
+  mpz_clear (t);
+  mpz_clear (z);
+  mpz_clear (x);
+  mpz_clear (y);
 }
 #endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]