How BigIntegers work in JavaScript
silentmatt.com
How BigIntegers work in JavaScript
1–10 of 15 posts
Re: How BigIntegers work in JavaScript
#2[edit] Ah ha, printed arrays have position zero on the left. I thought it was on the right.
Re: How BigIntegers work in JavaScript
#3Seriously, for the number -123, the array [3, 2, 1] has the least significant digit in position zero? [edit] Ah ha, printed arrays have position zero on the left. I thought it was on the right.
Rather than digits[2] for -123's least significant digit, and digits[1] for, say, 43's least significant digit.
Re: How BigIntegers work in JavaScript
#4Seriously, for the number -123, the array [3, 2, 1] has the least significant digit in position zero? [edit] Ah ha, printed arrays have position zero on the left. I thought it was on the right.
It's rather clever.
Re: How BigIntegers work in JavaScript
#5Seriously, for the number -123, the array [3, 2, 1] has the least significant digit in position zero? [edit] Ah ha, printed arrays have position zero on the left. I thought it was on the right.
The reason for putting the least significant digit first is that carries accumulate towards the most significant digit in ordinary arithmetic. Thus many of the simplest operations want to work from least significant to most significant digit. A final carry out at the top might add an extra digit to the result. It would be really annoying to work with arrays that had most significant digit first. If you had an extra digit you'd have to shift the entire array one place to accommodate it!
Re: How BigIntegers work in JavaScript
#6http://www.leemon.com/crypto/BigInt.js
It's about the best I've seen and embodies all the principles that are being explained by Matt.
Re: How BigIntegers work in JavaScript
#7Re: How BigIntegers work in JavaScript
#8So does this mean using biginteger for small numbers could require almost 30x more memory?
Re: How BigIntegers work in JavaScript
#9Seriously, for the number -123, the array [3, 2, 1] has the least significant digit in position zero? [edit] Ah ha, printed arrays have position zero on the left. I thought it was on the right.
Aka little endian. http://en.wikipedia.org/wiki/Endianness
Re: How BigIntegers work in JavaScript
#10So does this mean using biginteger for small numbers could require almost 30x more memory?