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

206                                        Chapter 7 Arithmetic Operations


            One could also handle underflows in the same way that one handles rounding. For
        example, the result of the subtraction


                                   2-126 * i.oilO .. . 0
                               -    2-126 * i.oooo . . . Q
                                   2-126 * 0.0110 .. . 0


         could be put equal to 0, and the result of the subtraction

                                   2-126 * i.ioiO .. . 0
                                   2-126 * i.oooo . . . Q
                                   2-126 * 0.1010 .. . 0

        could be put equal to 2~ 126  * 1.0000. More frequently, all underflow results are put
        equal to 0 regardless of the rounding method used for the other numbers. This is termed
        flushing to zero. The use of denormalized floating-point numbers appears natural here,
         as it allows for a gradual underflow as opposed to, say, flushing to zero. To see the
         advantage of using denormalized floating-point numbers, consider the computation of the
        expression (Y — X) + X. IfY- X underflows, X will always be the computed
        result if flushing to zero is used. On the other hand, the computed result will always be
         Y if denormalized floating-point numbers are used. The references mentioned at the end of
        the chapter contain further discussions on the merits of using denormalized floating point
         numbers. Implementing all of the arithmetic functions with normalized and denormalized
         floating-point numbers requires additional care, particularly with multiplication and
        division, to ensure that the computed result is the closest represented number, normalized
         or denormalized, to the exact result. It should be mentioned that the IEEE standard
         requires that a warning be given to the user when a denormalized result occurs. The
        motivation for this is that one is losing precision with denormalized floating-point
        numbers. For example, if during the calculation of the expression (Y — X) * Z. If Y
        -X underflows, the precision of the result may be doubtful even if (Y — X) * Zisa
         normalized floating-point number. Flushing to zero would, of course, always produce
        zero for this expression when (Y — X) underflows.
            The process of rounding to nearest, hereafter just called rounding, is straightforward
        after multiplication. However, it is not so apparent what to do after addition, subtraction,
         or division. We consider addition/subtraction. Suppose, then, that we add the two
         numbers


                                   20   * 1.0000 .. . 0
                               +   2-23 * 1.1110 . . . 0

         After unnormalizing the second number, we have


                                   20 * 1.0000 .. . 00
                               +   2° * 0.0000 . . . Qlflll)
                                   20 * 1.0000 . . . 01(111)
   224   225   226   227   228   229   230   231   232   233   234