Take the 2-minute tour ×

If anyone wants to know...

I was trying to figure out the largest integer that Javavscript could express that could be part of a continuous range of numbers. At first, I thought that just using Number.MAX_VALUE would work, but that was a silly assumption.

Javascript stores all numbers as double precision floating point numbers, following the IEEE 754 standard.

Number.MAX_VALUE is equal to

7fef ffff ffff ffff, approximately 1.7976931348623157e+308. 

The next smallest number that can be stored in this format would be

7fef ffff ffff fffe, approximately 1.7976931348623155e+308.

There is obviously quite a gap inbetween those two numbers that result in behaviors such as

Number.MAX_VALUE == (Number.MAX_VALUE-1) //true

Now, that doesn't scare me or anything, that's just the matter of fact. What I'm looking for is when this next condition is first true in JS

x == (x+1) //true
share|improve this question

1 Answer 1

Rather than writing a script that simply added in increments of 1 until the above condition was met, I noticed on the Wikipedia page for IEEE Double-Precision Floating Point the following text:

"Between 2^52=4,503,599,627,370,496 and 2^53=9,007,199,254,740,992 the representable numbers are exactly the integers. For the next range, from 2^53 to 2^54, everything is multiplied by 2, so the representable numbers are the even ones, etc."

So, it seems like 2^53 would be the high-end of the range of continuous integers, and was verified with

Math.pow(2,53) == Math.pow(2,53)+1 //true
Math.pow(2,53) == Math.pow(2,53)-1 //false

I actually don't need the low end to that range, but it could be interesting if someone knew what it was.

share|improve this answer
The range of integers that can be represented exactly in an IEEE double is -2^53+1 to 2^53-1. –  Joni Oct 2 '13 at 22:01
@Joni—I think you're correct, however there are quirks in some browsers at the extremes so the OP should test thoroughly. –  RobG Oct 2 '13 at 22:08
You might want to check this out if you're doing anything but research into this matter. –  rosscowar Oct 2 '13 at 22:24
@Joni, wouldn't the largest positive integer that can be represented be 2^53 (rather than 2^53-1) considering the inequality posted in my answer? Math.pow(2,53) == 9007199254740992 and Math.pow(2,53)-1 == 9007199254740991 –  MandM Oct 3 '13 at 17:53
But the difference can be shown between 2^53-1 and 2^53, or is the difference shown in the console's output due to rounding? –  MandM Oct 3 '13 at 18:01

Your Answer


