Page 232 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 232

7.5 Floating-Point Arithmetic and Conversion                         209


         1.  Attach a zero round byte to each significand and unnormalize the number with the
             smaller exponent.
         2,  Add significands of operands (including the round byte).
         3,  If an overflow occurs in the significand bits, shift the bits for the magnitude and
             round byte right one bit and increment the exponent.
         4.  If all bits of the unrounded result are zero, put the sign of the result equal to + and
             the exponent of the result to the most negative value; otherwise, renormalize the
             result, if necessary, by shifting the bits of the magnitude and round byte left and
             decrementing the exponent for each shift.
         5.  If underflow occurs, flush the result to zero, and set the underflow flag; otherwise,
             round the result.
        6,   If overflow occurs, put the magnitude equal to the maximum value, and set the
             overflow flag.

                       Figure 7.20. Procedure for Floating-Point Addition

            Converting the decimal fraction into a binary floating-point number can be carried
        out in two steps.
         1. Convert the decimal fraction to a binary fraction.
         2, Convert the binary fraction to a binary floating-point number.
        Step 2 is straightforward, so we concentrate our discussion on Step 1, converting a
        decimal fraction to a binary fraction.
            Converting fractions between different bases presents a difficulty not found when
        integers are converted between different bases. For example, if




        is a base-r fraction, then it can happen that when f is converted to a base-s fraction.




        that is, bi is not equal to 0 for infinitely many values of i. (As an example of this,
        expand the decimal fraction 0.1 into a binary one.) Rather than trying to draw analogies
        to the conversion of integer representations, it is simpler to notice that multiplying the
        right-hand side of (18) by s yields bi as the integer part of the result, multiplying the
        resulting fractional part by s yields b 2 as the integer part, and so forth. We illustrate the
        technique with an example.
            Suppose that we want to convert the decimal fraction .345786 into a binary fraction
        so that

                                             l         2
                            .345786 = b x * 2~  + b 2 * 2"  + ...
        Then bi is the integer part of 2 * (.345786), b2 is the integer part of 2 times the
        fractional part of the first multiplication, and so on for the remaining binary digits. More
        often than not, this conversion process from a decimal fraction to a binary one does not
   227   228   229   230   231   232   233   234   235   236   237