Problem with mpz_tstbit on Windows...

Marc Glisse marc.glisse at inria.fr
Sat Feb 4 20:06:34 UTC 2017


On Sat, 4 Feb 2017, wraithx at morpheus.net wrote:

> I recently found out that mpz_tstbit does not always work as expected on 
> Windows.  I found this out while using GMP 6.1.1, but looking at the source, 
> it seems like this problem has been around since at least GMP 4.x up to GMP 
> 6.x. The problem occurs when passing a 64-bit index into mpz_tstbit.  Since 
> the function uses an unsigned long for the index, the index is truncated to 
> 32-bits on Windows computers and will return incorrect results when the index 
> is >= 2^32.

This is not specific to tstbit. We have a typedef mp_bitcnt_t for bit 
indices, I believe the reason we haven't changed it to 64 bits on windows 
is binary compatibility with older versions. Maybe GMP-7 would be a good 
time to change that...

-- 
Marc Glisse


More information about the gmp-bugs mailing list