|
From: | Pádraig Brady |
Subject: | bug#12350: Composites identified as primes in factor.c (when HAVE_GMP) |
Date: | Mon, 08 Oct 2012 23:39:25 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 |
On 10/08/2012 03:47 PM, Pádraig Brady wrote:
diff --git a/src/factor.c b/src/factor.c index 5bfbfdc..843542b 100644 --- a/src/factor.c +++ b/src/factor.c @@ -526,6 +526,29 @@ factor_insert_large (struct factors *factors, } #if HAVE_GMP + +# if !HAVE_DECL_MPZ_INITS + +# define mpz_inits(...) mpz_va_init (mpz_init, __VA_ARGS__) +# define mpz_clears(...) mpz_va_init (mpz_clear, __VA_ARGS__) + +static void +mpz_va_init (void (*mpz_single_init)(mpz_t), mpz_ptr mpz, ...) +{ + va_list ap; + + va_start (ap, mpz); + + while (mpz != NULL) + { + mpz_single_init (mpz); + mpz = va_arg (ap, mpz_ptr); + } + + va_end (ap); +} +# endif + static void mp_factor (mpz_t, struct mp_factors *);
Actually the above doesn't order the va_arg() call correctly. Also it uses mpz_ptr which is not kosher it seems: http://gmplib.org/list-archives/gmp-discuss/2009-May/003769.html So I've adjusted to: #define mpz_inits(...) mpz_va_init (mpz_init, __VA_ARGS__) #define mpz_clears(...) mpz_va_init (mpz_clear, __VA_ARGS__) static void mpz_va_init (void (*mpz_single_init)(mpz_t), ...) { va_list ap; va_start (ap, mpz_single_init); mpz_t *mpz; while ((mpz = va_arg (ap, mpz_t *))) mpz_single_init (*mpz); va_end (ap); } cheers, Pádraig.
[Prev in Thread] | Current Thread | [Next in Thread] |