2.3.1 RANGE AND PRECISION IN FLOATING POINT NUMBERS
A ﬂoating point representation allows a large range of expressible numbers to be represented in a small number of digits by separating the digits used for precision from the digits used for range. The base 10 ﬂoating point number representing Avogadro’s number is shown below:
+6.023 × 1023
Here, the range is represented by a power of 10, 1023 in this case, and the precision is represented by the digits in the ﬁxed point number, 6.023 in this case. In discussing ﬂoating point numbers, the ﬁxed point part is often referred to as the mantissa,
or signiﬁcand of the number. Thus a ﬂoating point number can be characterized by a triple of numbers: sign, exponent, and signiﬁcand.
The range is determined primarily by the number of digits in the exponent (two digits are used here) and the base to which it is raised (base 10 is used here) and the precision is determined primarily by the number of digits in the signiﬁcand (four digits are used here). Thus the entire number can be represented by a sign and 6 digits, two for the exponent and four for the signiﬁcand. Figure 2-7 shows how the triple of sign, exponent, signiﬁcand, might be formatted in a computer.
Figure 2-7 Representation of a base 10 floating point number.
Notice how the digits are packed together with the sign ﬁrst, followed by the exponent, followed by the signiﬁcand. This ordering will turn out to be helpful in comparing two ﬂoating point numbers. The reader should be aware that the decimal point does not need to be stored with the number as long as the decimal point is always in the same position in the signiﬁcand. (This will be discussed in Section 2.3.2.)
If we need a greater range, and if we are willing to sacriﬁce precision, then we can use just three digits in the fraction and have three digits left for the exponent without increasing the number of digits used in the representation. An alternative method of increasing the range is to increase the base, which has the effect of increasing the precision of the smallest numbers but decreasing the precision of the largest numbers. The range/precision trade-off is a major advantage of using a ﬂoating point representation, but the reduced precision can cause problems, sometimes leading to disaster, an example of which is described in Section 2.4.