2 minor issues on Windows

sisyphus sisyphus359 at gmail.com
Wed Jan 19 14:10:10 CET 2022


On Sun, Jan 16, 2022 at 9:24 PM George Woltman <woltman at alum.mit.edu> wrote:


> The problem is that while _LONG_LONG_LIMB is defined, the definition of
> mp_bitcnt_t ought to also use "long long".
> I get this compiler warning calling mpz_tstbit:  warning C4244: 'argument':
> conversion from 'uint64_t' to 'mp_bitcnt_t', possible loss of data
> Yes, I'm creating mpz values with more than 4 billion bits.
>

On windows, we're faced with the irritating fact that sizeof(mp_bitcnt_t)
is always 4 bytes. (This is a general Windows issue that's not limited to
just MSVC.)
I think the gmp developers are aware of this, and that removing this
annoyance is on a todo list.

I once tried hacking the gmp source such that 'unsigned long long int'
would be typedeffed to 'mp_bitcnt_t', but I couldn't get much mileage out
of my attempts.
(You could try the same, and see how it goes.)

In the end I decided that, on Windows, if I currently want to mpz_tstbit()
a bit beyond index 4294967295, then I first have to perform
a 4294967295-bit right-shift on the mpz_t (or on a copy thereof), and then
query the relevant bit
For example, if I want to mpz_tstbit() the bit at index 4294967296, I first
right-shift the value by 4294967295 bits (using mpz_tdiv_q_2exp), and then
mpz_tstbit() the bit at index 1.

Cheers,
Rob


More information about the gmp-bugs mailing list