Search code examples
gmp

GMP variable's bit size


How to know the size of a declared variable in GMP??or how can we decide the size of an integer in GMP?

mpz_random(temp,1);

in manual it is given that this function allocates 1limb(=32bits for my comp) size to the "temp".... but it is having 9 digit number only.. SO i dont think that 32 bit size number holds only 9 digits number..

So please help me to know the size of integer variable in GMP ..

thanks in adv..


Solution

  • 32 bits (4 bytes) really can be used to store only 9 decimal digits

    2^32 = 4 294 967 296
    

    so only 9 full decimal digits here (the 10th is in interval from 0 up 4, so it is not full).

    You can recompute this via logarithms:

    log_10(2^32)
    

    let's ask google

    log base 10(2^32) = 9.63295986
    

    Everything is correct.