Jacques Gélinas on Mon, 30 Jan 2017 19:21:28 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Number of 32-bit words in an integer


You first need the number of bits in a word, and this is what I use:

/* PARI/GP floating point [base, words, bits, meps] */

flpari(p=precision(1.)) = {
  local( w = #precision(1.,p) );
  [2, w, w*=64/#precision(1.,18), 2.>>w];
}
addhelp(flpari,"flpari(p): parameters of p-decimal PARI/GP floating-point arithmetic \
                                    [base, words, bits, machine epsilon]")


Next, #(2^257-1) will give 5 on a 64-bit machine, but 9 on a 32-bit machine
while #(2^256-1) will give 4 on a 64-bit machine, but 8 on a 32-bit machine, 
so maybe you can use

words(N=2^256-1) = round( #N / precision(1.,18)  )

but there should be a simpler way avoiding the use of floating-point and rounding ?

Jacques Gélinas