Is this defined by the language? Is there a defined maximum? Is it different in different browsers?
views:
11723answers:
5From the reference
alert( [Number.MAX_VALUE, Number.MIN_VALUE] );
they are 64-bit floating point values, the largest exact integral value is 2^53. however, from the spec section [8.5: Number Type]:
Some ECMAScript operators deal only with integers in the range −2^31 through 2^31−1, inclusive, or in the range 0 through 2^32−1, inclusive. These operators accept any value of the Number type but first convert each such value to one of 2^32 integer values. See the descriptions of the ToInt32 and ToUint32 operators in sections 0 and 0, respectively
Firefox 3 doesnt seem to have a problem with huge numbers.
1e+200 * 1e+100 will calculate fine to 1e+300.
Safari seem to have no problem with it aswell. (For the record, this is on a Mac if anyone else decides to test this)
Unless I lost my brain at this time of day, this is way bigger than a 64-bit integer.
I did a simple test with a formula X-(X+1)=-1 and the largest value of X I can get to work on Safari, Opera and Firefox (tested on OSX) is 9e15. Here is the code I used for testing:
javascript: alert(9e15-(9e15+1));