Programming and Problem Solving with Java

(やまだぃちぅ) #1

(^594) | Multidimensional Arrays and Numeric Computation



  • 199 9 9
    NUMBER POWER OF TEN
    NOTATION CODED REPRESENTATION VALUE
    +99,999



  • 999,999


+1,000,000


  • 4,932,416


+99,999


  • 999,999


+1,000,000


  • 4,932,416


+9999 × 101

– 9999 × 102

– 1000 × 103

– 4932 × 103

Sign Exp


  • 299 9 9


Sign Exp

+ 310 0 0

Sign Exp


  • 349 3 2


Sign Exp

Figure 12.7 Coding Using Positive Exponents

++99 99


  • +99 99


+ – 9000

–– 9000

9

9

1

1

Sign Exp

Sign of
number

Sign of
exponent

Largest positive number: +9999 10^9

Largest negative number: –9999 10^9

Smallest positive number: +1 10–^9

Smallest negative number: –1 10–^9

Figure 12.8 Coding Using Positive and Negative Exponents

Because our scheme does not include a sign for the exponent, let’s change it slightly. The ex-
isting sign becomes the sign of the exponent, and we add a sign to the far left to represent
the sign of the number itself (see Figure 12.8).
We can now represent all the numbers between  9999  109 and 9999  109 accurately
to four digits. Adding negative exponents to our scheme allows us to represent fractional num-
bers as small as 1  10 ^9.
Figure 12.9 shows how we would encode some floating-point numbers. Note that our pre-
cision remains four digits. The numbers 0.1032,5.406, and 1,000,000 can be represented ex-
actly. The number 476.0321, however, has seven significant digits but is represented as 476.0;
Free download pdf