Page 299 - ARM 64 Bit Assembly Language
P. 299

288 Chapter 8

                  7. Combine the sign S r , the exponent E r , and significand M r to form the result.

                  The complete algorithm must also provide for correct handling of infinity and NaN.


                  8.8.2 Floating point multiplication and division

                  Multiplication and division of floating point numbers also requires several steps. The steps for
                  multiplication and division of two floating point numbers a and b are as follows:
                  1. Calculate the sign of the result S r .
                  2. Extract the exponents E a and E b .
                  3. Extract the significands M a and M b .
                  4. Multiply (or divide) the significands to form M r .
                  5. Add (or subtract) the exponents (in excess-N) to get E r .
                  6. Shift M r until the leftmost 1 is in the “hidden” bit position, and add the shift amount to
                     E r .
                  7. Combine the sign S, the exponent E r , and significand M r to form the result.

                  The complete algorithm must also provide for correct handling of infinity and NaN.


                  8.9 Ethics case study: patriot missile failure

                  Fixed point arithmetic is very efficient on modern computers. However it is incumbent upon
                  the programmer to track the radix point at all stages of the computation, and to ensure that a
                  sufficient number of bits are provided on both sides of the radix point. The programmer must
                  ensure that all computations are carried out with the desired level of precision, resolution,
                  accuracy, range, and dynamic range. Failure to do so can have dire consequences.

                  On February 25, 1991, during the Gulf War, an American Patriot Missile battery in Dha-
                  ran, Saudi Arabia, failed to intercept an incoming Iraqi SCUD missile. The SCUD struck an
                  American army barracks, killing 28 soldiers and injuring around 98 other people. The cause
                  was an inaccurate calculation of the time elapsed since the system was last booted.
                  The hardware clock on the system counted the time in tenths of a second since the last reboot.
                  Current time, in seconds, was calculated by multiplying that number by  1  . For this calcu-
                                                                                 10
                  lation,  1  was represented as a U(1,23) fixed point number. Since  1  cannot be represented
                        10                                                  10
                  precisely in a fixed number of bits, there was round-off error in the calculations. The small
                  imprecision, when multiplied by a large number, resulted in significant error. The longer the
                  system ran after boot, the larger the error became.

                  The system determined whether or not it should fire by predicting where the incoming missile
                  would be at a specific time in the future. The time and predicted location were then fed to a
   294   295   296   297   298   299   300   301   302   303   304