Hi,
Still struggling. I'd like some help to find my mistake trying to understand
the Ersatz version of initSeed. The source is here, if you don't have it handy:
https://code.google.com/p/picolisp/source/browse/ersatz/sys.src#234

final static long initSeed(Any x) {

Means it gives back a signed 64 bits integer for anything we threw at
it (called x).


long n; for (n = 0; x instanceof Cell; x = x.Cdr) n += initSeed(x.Car);

Is a recursive trick that walks through x (if walkable, ie Cell) and cumulates
in n the results of initSeed for anything non walkable that was thrown at it.


if (x != Nil) {…

When the non walkable is not a list termination…


if (x instanceof Number && ((Number)x).Big == null) n += ((Number)x).Cnt;

If x is a 32 bits integer, just add it to n (not sure about the (Number) cast,
Number doesn't seem to have children).


else {
byte b[] = x instanceof Symbol? x.name().getBytes() :
((Number)x).Big.toByteArray();
for (int i = 0; i < b.length; ++i)
n += b[i];
}

If x is not a 32 bits int, get a bytes array (via its name if it is a
sym, or via its
array of bytes if it is a Java BigInteger, and cumulates the bytes in n.


return n>=0? n*2 : -n*2+1;

This ensures the return value is non negative (?).
But why would not the result overflow?


Now if I'm correct until here, initSeed(1) should just return 2.
Then I don't understand why (seed 1) returns -5718471626015965606,
since (seed x) just multiplies the result of initSeed(x) by 6364136223846793005,
and 2*6364136223846793005<2^64 (no overflow).

See here for the source:
https://code.google.com/p/picolisp/source/browse/ersatz/fun.src#3308
only two lines:
n = initSeed(ex.Cdr.Car.eval()) * 6364136223846793005L;
return new Number(Seed = n);

Thanks reading so far !


chri

-- 

http://profgra.org/lycee/ (site pro)
http://delicious.com/profgraorg (liens, favoris)
https://twitter.com/profgraorg
http://microalg.info
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to