tags:

views:

118

answers:

2

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..

+1  A: 

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.

You can recompute this via logarithms:

log_10(2^32)

let's ask google

log base 10(2^32) = 9.63295986

Everything is correct.

osgx
+1  A: 

You can check the number of limbs in a debugger. A GMP integer has the internal field '_mp_size' which is the count of the limbs used to hold the current value of the variable (0 is a special case: it's represented with _mp_size = 0). Here's an example I ran in Visual C++ (see my article How to Install and Run GMP on Windows Using MPIR):

mpz_set_ui(temp, 1073741824); //2^30, (_mp_size = 1)
mpz_mul(temp,temp,temp); //2^60 (_mp_size = 2)
mpz_mul(temp,temp,temp); //2^120 (_mp_size = 4)
Rick Regan
Yea.. you are correct..._mp_size returns number of limbs of an integer..that means we can create integers of size 1limb(32bits),2limbs(64bits),3limbs(96bits)...so on.cant we create an integer variable of size 8bit or 16 bit.. other than multiples of 32???
kishorebjv