views:

11723

answers:

5

Is this defined by the language? Is there a defined maximum? Is it different in different browsers?

+16  A: 

From the reference

alert( [Number.MAX_VALUE, Number.MIN_VALUE] );

Peter Bailey
I've edited the question to be a bit more precise about wanting the max Integer values, not just the max Number value. Sorry for the confusion, here.
TALlama
+7  A: 

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

Jimmy
This seems right, but is there someplace where this is defined, á la C's MAX_INT or Java's Integer.MAX_VALUE?
TALlama
according to IEEE_754 standard, 64-bit floating point uses 53 bits for the mantissa. As far as a javascript constant, I'm not aware of any.
Jimmy
A: 

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.

jishi
its not a 64 bit integer, its a 64-bit floating point number, of which 52/53 bits are the integer portion. so it will handle up to 1e300, but not with exact precision.
Jimmy
+1  A: 

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));
Raynet
Note that 9e15 = 2^53 (see @Jimmy's answer).
Wedge
A: 

maxInt = -1 >>> 1

in Firefox 3.6 it's 2^31 - 1.

Martin Naatz