"how numbers are stored in computers"
Floating point numbers represent numeric values in a binary form of scientific notation (
0
is positive and 1
is negative.JavaScript uses 64-bit IEEE 754 double precision format for all numbers. This means that each 64 bit number uses 1 bit for the sign, 11 bits for the exponent, and 52 bits for the significand.
signexponentsignificand
The equation for computing a decimal value from the binary representation above is
Let's try to first understand this intuitively. The exponent is really just an interval between two successive powers of 2, like
As a floating point number gets larger, it "floats" to the next interval, and as it gets smaller, it "floats" to the previous interval. Intervals closer to zero are "more dense", in the sense that the significand provides a more precise number along that interval.
The significand is being displayed as a number, but it actually represents the sequence of binary digits of a normalized value which takes the form
You will often see floating point numbers written in scientific notation (
In floating point arithmetic and associated proofs, a floating point number is typically written as