Overall the code is really well done and clear. However here is some issues I ran into:
bignum_from_js: Using ">>" and "&" breaks when n is not representable on 32 bits, see 11.7.2 and 11.10 in ECMAScript 5.
Ex:
d8> Math.pow(2,30) >> 29 2
d8> Math.pow(2,32) >> 31 0
Bitwise arithmetic in javascript is done on 32 bits integer. That means we cannot create a bignum from a js number which takes more than 32 bits to represent.
bignum_mod: In javascript, the sign of the result is the sign of the dividend, see 11.5.3 (ES 5). For uniformity, I think we might want to stick to the same convention.
Erick
Afficher les réponses par date
On 2011-02-22, at 3:56 PM, Erick Lavoie wrote:
Overall the code is really well done and clear. However here is some issues I ran into:
bignum_from_js: Using ">>" and "&" breaks when n is not representable on 32 bits, see 11.7.2 and 11.10 in ECMAScript 5.
Ex:
d8> Math.pow(2,30) >> 29 2
d8> Math.pow(2,32) >> 31 0
Bitwise arithmetic in javascript is done on 32 bits integer. That means we cannot create a bignum from a js number which takes more than 32 bits to represent.
bignum_mod: In javascript, the sign of the result is the sign of the dividend, see 11.5.3 (ES 5). For uniformity, I think we might want to stick to the same convention.
I'll look into this issue tonight.
Marc
On 2011-02-22, at 3:56 PM, Erick Lavoie wrote:
Overall the code is really well done and clear. However here is some issues I ran into:
bignum_from_js: Using ">>" and "&" breaks when n is not representable on 32 bits, see 11.7.2 and 11.10 in ECMAScript 5.
Ex:
d8> Math.pow(2,30) >> 29 2
d8> Math.pow(2,32) >> 31 0
Bitwise arithmetic in javascript is done on 32 bits integer. That means we cannot create a bignum from a js number which takes more than 32 bits to represent.
I'm not sure what the "right thing to do" is in this case. We want to avoid a Math.floor(a/b) because while we are bootstrapping we don't yet have floating point division. Moreover, considering the first bootstrap will be on a 32 bit machine, we should never have a native JS number that doesn't fit in a fixnum. So a bignum_from_js(Math.pow(2,32)) should never occur. If you want a large number, then use num.js to compute it, such as num_shift(1,32), to compute 2^32.
In any case, for the moment, we can ignore that ">>" and "&" operate on 32 bits. We can simply do the operation on all the bits in the fixnum (either 30 when in 32 bit mode, or 62 when in 64 bit mode).
bignum_mod: In javascript, the sign of the result is the sign of the dividend, see 11.5.3 (ES 5). For uniformity, I think we might want to stick to the same convention.
Fixed.
Marc