On Tue, Apr 28, 2015 at 8:38 AM, Alexander Burger <a...@software-lab.de> wrote:
> Good, but this is not completely correct. It stores the reduced 32-bit
> value in 'Seed'. I think 'Seed' must keep the full 64-bit value.
Indeed. I'm not used to read lines with interleaved affectations.
> I changed it to
> return new Number((int)((Seed = initSeed(ex.Cdr.Car.eval()) *
> 6364136223846793005L) >>> 32));
> which is also more analog to pil32. What do you think?
That the results are analog, but different. To obtain exactly the same
results that pil32,
I had to write:
long n = (Seed = initSeed(ex.Cdr.Car.eval()) * 6364136223846793005L) >>> 32;
return new Number(n%2==0 ? n/2 : -(n-1)/2);
This is the same trick than the one I used to mimic (rand).
See below what I wrote on april the 26th in the other thread:
2)b) I got stuck when trying to mimic the (rand) of pil32.
In doRand, at this line in big.c:
In Ersatz in rand (x n)
at this line:
return new Number((int)Seed);
This seemed so similar that I banged my head on the screen showing
the discrepancies between the results of pil32 and Ersatz that I couldn't
Then, I noticed a pattern, that leaded to reversing the sign bit trick you
just explained in initSeed: n>=0? n*2 : -n*2+1;
One the one hand, Ersatz takes the lower 32 bits of the seed,
then returns them as a signed integer. But on the other hand,
pil32 takes the higher 32 bits as n (unsigned integer) and returns
n%2==0 ? n/2 : -(n-1)/2.
A question: why did you choose different implementations ?
Is it for a better efficiency in Ersatz ?
> Again, thanks for the input!
Again, this is really nice to have someone who really takes the time to listen.
Thank you Alex.
http://profgra.org/lycee/ (site pro)
http://delicious.com/profgraorg (liens, favoris)