How does one calculate 2 ^ -18 ?

Vincent Lefevre vincent at vinc17.org
Wed Jan 7 17:33:23 CET 2009


On 2009-01-07 13:43:53 -0200, Décio Luiz Gazzoni Filho wrote:
> 2^-18 is not an integer, so it's no surprise that you didn't get a  
> meaningful result out of trying to do an integer powering operation  
> (mpz_pow). Whether that was a crash or an invalid value is beside the  
> point. Just so you know, mpz_pow_ui actually takes an (u)nsigned  
> (i)nteger as an exponent, as the name says. So rather than compute  
> 2^(-18), you computed something like 2^4294967278 assuming you were on  
> a 32-bit computer, or maybe 2^18446744073709551598 if you were on a 64- 
> bit computer, due to 2's complement representation of integers in your  
> computer.

Here this has nothing to do with 2's complement representation. This
is just a rule of the C standard (the behavior must be the same with
other representations of integers -- though more work may be needed
by the compiler).

> GMP probably just ran out of memory -- although it's a `mere' 512 MB
> of RAM for the 32-bit case, I assume you can't allocate that much
> memory on the stack without special measures.

But GMP no longer uses the stack for huge numbers.

> Now if you're actually looking for the numbers 1/262144 or  
> 0.000003814697265625, maybe you should be using mpq or mpf instead.

Or MPFR.

-- 
Vincent Lefèvre <vincent at vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


More information about the gmp-discuss mailing list