How does one calculate 2 ^ -18 ?

David Gillies daggillies at
Wed Jan 7 15:29:16 CET 2009

Why are you using the integer interface to calculate 1/262144? And
what does the U in mpz_pow_ui() tell you? Passing -18 made GMP think
you were raising 2 to the power 4294967270, which fairly obviously
blew up.

On Tue, Jan 6, 2009 at 8:50 PM, Bruce M. Axtens <bruce.axtens at> wrote:
> Please pardon the mathematical naivete: I passed -18 to mpz_pow_ui and
> the code crashed. No surprises there ("read the friendly manual, you
> goose!")  So I went back to the manual and tried to get my mind around
> mpz_powm and related things. I'm still as confused as before. Please,
> someone, take pity on me and demonstrate in a bit of C how to raise 2 to
> the negative 18.

David Gillies
San Jose
Costa Rica

More information about the gmp-discuss mailing list