Number Representations & States

"how numbers are stored in computers"

Floating point numbers

Floating point numbers represent numeric values in a binary form of scientific notation (). Each number consists of three parts:

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

Floating point intuition

Let's try to first understand this intuitively. The exponent is really just an interval between two successive powers of 2, like , , and so on. The significand is simply the offset within this interval. To see what this looks like, try entering values below to see their floating point decomposition, or click along the number line to see the sign, exponent, and significand change.


=


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 . When we know the first digit is always a 1, we can actually get an extra bit of precision for free - this is called the hidden bit trick.

You will often see floating point numbers written in scientific notation (), but as you can see, this does not indicate a standard multiplication operation.

Floating point proofs

In floating point arithmetic and associated proofs, a floating point number is typically written as , where represents digits of the significand, is the base, and is the exponent.