What's in a Number?
What is the range of numbers in JS?
Naively one may assume that querying the biggest and smallest numbers
// largest natural number which can be represented by a Number Number.MAX_VALUE 1.7976931348623157e+308 Number.MIN_VALUE 5e-324 // smallest non-zero number Number.MIN_VALUE > 0 true Number.MAX_VALUE < Infinity true
53 bits is not enough to represent the
10^308 stated above.
So at what point can we no longer count any more?
Well 53 bits can represent up to:
Math.pow(2, 53) - 1; 9007199254740991 // ~~ 9×10^15
Handily this number is a constant on the Number object:
Number.MAX_SAFE_INTEGER 9007199254740991 Number.MIN_SAFE_INTEGER -9007199254740991
Beyond this limit you start to lose precision.
Number.MAX_SAFE_INTEGER + 1 9007199254740992 Number.MAX_SAFE_INTEGER + 2 9007199254740992 Number.MAX_SAFE_INTEGER + 3 9007199254740994
What can we precisely represent with limit?
So what exactly can one count with 9 Quadrillion?
Lot’s of fun on wikipedia: https://en.wikipedia.org/wiki/Category:Orders_of_magnitude
- This is about 500× US Debt in Dollars
- Number of Synapses in the Human Brain is of this Magnitude
- Number of atoms in about 10 nanograms of material.
- Earths atmosphere is about 5×10^15 Tons
- One Quadrillion Pennies
- One quadrillion seconds is about 31M years.
- One quadrillion meters is about 6685 × The distance between the Earth and Sun. (~0.1 light years).
- One quadrillion bytes is a Petabyte.
I initially thought the Date object would only be limited by the max integer.
new Date(Number.MAX_SAFE_INTEGER) Invalid Date // Awww
Apparently it is limited to one hundred million days (
10^12) days either side of 1/1/1970 which is
100000000*24*3600*1000 = 8640000000000000ms. About 95% of the
Unfortunately on a cosmological scale (Billions of years) this timeline is nothing. It doesn’t really scratch the age of the sun. (5 Billion years)
Nor does it even approach a geological timeline. Pangea broke apart 200 million years ago.
But it does encompass human history quite nicely: Modern humans evolved and started migrating from africa about 200,000 years ago.
Although I doubt early homo sapiens would have much use for milisecond levels of precision.