Programming and Problem Solving with Java

(やまだぃちぅ) #1
12.5 F l o ating-Point Numbers | 593

ing-point variable or constant, the number stored there has both a whole-number part and
a fractional part, so we must code it to represent both parts.
Let’s see what such coded numbers might look like. The range of whole numbers we
can represent with five digits is 99,999 through +99,999:


Our precision(the number of digits we can represent) is five digits, and
each number within that range can be represented exactly.
What happens if we allow one of those digits (the leftmost one, for ex-
ample) to represent an exponent?


Then +82345 represents the number +2345  108. The range of numbers we now can
represent is much larger:


 9999  109 through 9999  109
or
9,999,000,000,000 through +9,999,000,000,000
However, our precision is now only four digits; that is, only four-digit
numbers can be represented exactly in our system. What happens to num-
bers with more digits? The four leftmost digits are represented correctly, and
the rightmost digits, or least significant digits, are lost (assumed to be 0).
Figure 12.7 shows the result. Note that 1,000,000 can be represented exactly
but 4,932,416 cannot, because our coding scheme limits us to four significant
digits.
To extend our coding scheme to represent floating-point numbers, we
must be able to represent negative exponents. Examples are


7394  10 ^2 = 73.94
and
22  10 ^4 = .0022

Exponent

+82345

–99999 through +99999
Largest positive number

Largest negative number

Zero

+99999


  • 99999


+00000

Precision The maximum num-
ber of significant digits

Significant digits Those digits
from the first nonzero digit on
the left to the last nonzero digit
on the right (plus any 0 digits
that are exact)
Free download pdf