0

Possible Duplicate:
What is JavaScript's Max Int? What's the highest Integer value a Number can go to without losing precision?

What is the maximum integer in javascript? I have a variable that starts in 0 and adds 100 each 0.1 seconds. What is the maximum number it can reach?

BTW, I thought this question had been answered before but I couldn't find it. If it is answered, please send me a link to it =) thanks!

0

3 Answers 3

2

JavaScript numbers are IEE 794 floating point double-precision values. There's a 53-bit mantissa (from memory), so that's pretty much the limit.

Now there are times when JavaScript semantics call for numbers to be cast to a 32-bit integer value, like array indexing and bitwise operators.

Sign up to request clarification or add additional context in comments.

Comments

2

A javascript variable can have any value you like. If native support isn't sufficient, there are various libraries that provide support for unlimited precision arithmetic (e.g. BigInt.js).

The largest value for the ECMAScript Number Type is +ve infinity (but infinity isn't a number, it's a concept). The largest numeric value is given by Number.MAX_VALUE, which is just the maximum value representable by an IEEE 754 64-bit double-precision number.

Some quirks:

var x = Number.MAX_VALUE;
var y = x - 1;
var z = x - 2;

x == y; // true
x == z; // false

The range of contiguous integers representable in ECMAScript is from -2^53 to +2^53. The largest exponent is 2^1023.

Comments

1

It is 1.7976931348623157e+308

to try it yourself code it

CODE

alert(Number.MAX_VALUE);

http://jsfiddle.net/XHcZx/

6 Comments

That's not what was asked, I don't think. The question explicitly says integer, and I suspect that means the OP is interested in the ability to represent a continuous sequence of integers. If you subtract 1 from that value, you won't really get that number minus 1.
That's great, thanks. I wasn't aware of the Number.MAX_VALUE property, which in fact shows what is supposed to be the largest possible number in javascript.
@jpatiaga you should be clear in your question - the words integer and number mean different things!
(Though admittedly, that value is an integer :-)
According to ECMA-262 §15.7.3.2, that is an approximation of the largest positive finite value of the Number type. You can't construct a continuous sequence of numbers from zero, e.g. Number.MAX_VALUE - 1 == Number.MAX_VALUE // true.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.