danaj / Math-Prime-Util-GMP

Perl prime number module using XS/GMP
Other
17 stars 9 forks source link

Add typedef for int32_t when using MSVC #6

Closed andygrundman closed 8 years ago

andygrundman commented 8 years ago

int32_t is used in one place in factor.c and needs to be defined here for MSVC.

andygrundman commented 8 years ago

I also have another problem with the ancient MSVC I'm using. I'm getting an infinite loop in t/17-pseudoprime.t the first time it calls is_perrin_pseudoprime (for 271441). I traced it to this loop in mat_powmod_3x3 being always true:

while (mpz_sgn(k)) {
    if (mpz_odd_p(k))  mat_mulmod_3x3(res, m, n, t, t2);
    mpz_fdiv_q_2exp(k, k, 1);
    if (mpz_sgn(k))    mat_mulmod_3x3(m, m, n, t, t2);
}

I'm using Visual Studio 98 for various reasons, so it's likely just a weird bug/issue with that, but if you have an idea on what could be going wrong, let me know. All other tests are passing, by the way. Thanks!

danaj commented 8 years ago

Thanks. It looks like the full set was done in the MPU ptypes.h, but not here. I'll add them all.

The 3x3 issue is interesting. We're shifting k down by 1 each loop, so it should always hit zero. I've never seen that, so can't easily debug. Perhaps try "while (mpz_sgn(k) > 0) {" or "while (mpz_cmp_ui(k,1) >= 0) {" or replace the fdiv line with "mpz_tdiv_q_ui(k, k, 2);" I hope it isn't the latter, but it'd be nice to see if any of those make a difference.