How does one calculate 2 ^ -18 ?
Torbjorn Granlund
tg at swox.com
Wed Jan 7 16:02:37 CET 2009
"Bruce M. Axtens" <bruce.axtens at gmail.com> writes:
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.
2^(-18) is not an integer. If you calculate it somehow and store it as
an mpz_t, you will get one of the integers 0 or 1, depending on which
functions you use.
A separate problem is the interpretation of -18 as the C type "unsigned
long", which is what mpz_pow_ui expects. It will be intepreted as a
very large integer (typically 2^32-18 or 2^64-18, depending on your
computer).
--
Torbjörn
More information about the gmp-discuss
mailing list