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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With