Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 4250 Computer Architectures September 12, 2006 Appendix H. Computer Arithmetic.

Similar presentations


Presentation on theme: "CSC 4250 Computer Architectures September 12, 2006 Appendix H. Computer Arithmetic."— Presentation transcript:

1 CSC 4250 Computer Architectures September 12, 2006 Appendix H. Computer Arithmetic

2 Five Real Stories on Computer Arithmetic 1. Insufficient Accuracy 2. Truncation Errors 3. Numerical Overflow 4. Divide by Zero 5. Wrong Units of Measurement

3 1. Insufficient Accuracy First Iraq War Feb 25, 1991; Dhahran, Saudi Arabia Iraqi Scud Missile American Patriot Missile failed to intercept 28 American soldiers died in the attack:  20% of the 148 total deaths

4 Fixed Point Data Patriot system contains an internal clock, a counter that is incremented every 0.1 seconds Time in seconds is determined by multiplying the counter value by 0.1 (24 bit approximation)

5 Approximation Base 10Base 2 0.1=0.000110011001100[1100]… ≈0.00011001100110011001100 ← 23 bits → Let x=0.00011001100110011001100 Then 0.1 − x =0.110011001100[1100]…× 2 –23 =0.00011001100[1001]…× 2 –20 Thus, (0.1 − x)/0.1 =2 –20 ←relative error

6 Patriot System Mobile system Designed to avoid detection Should run for only a few hours at each site Ran for 100 hours in Dhahran: 100 hrs = 360,000 sec = 3.6×10 5 sec Accumulated error equals (3.6×10 5 ) × 2 –20 = 0.3433 seconds > Clock step size

7 Software System Upgrade Software (assembly language) written in 1970s Modified to cope with high speed of missiles → Clock time more accurately converted Not all function calls replaced by new code Patriot likely confused by different clock times Patriot did not track the Scud → No Patriot missile was fired

8 2. Truncation Errors Dow Jones Industrial Average equals a multiple of the total prices of the 30 underlying stocks Present multiple is about 8.00 If IBM ($79.40, closing price on 9/7) goes up $1, then DJI average goes up 8.00 points If Microsoft ($25.43, closing price on 9/7) goes up $1, then DJI average goes up 8.00 points If GE ($34.04, closing price on 9/7) goes up $1, then DJIA goes up 8.00 points Is DJIA a good measure of the market? What happens to DJIA when IBM goes up 10%? MSFT? Faster to update index than to compute it from definition

9 Market Cap CompanyPriceMarket Cap IBM$79.40$121.96B MSFT$25.43$255.53B GE$34.04$350.17B

10 Effect on DJIA If the market cap of IBM goes up $12.196B, the DJIA will go up ?? points If the market cap of MSFT goes up $25.553B, the DJIA will go up ?? points If the market cap of GE goes up $35.017B, the DJIA will go up ?? points The S&P 500 index is generally regarded as a better measure of the market because it takes market cap into account (it is float weighted)

11 Truncation Errors (2) Vancouver Stock Exchange introduced new stock index in 1982 Updated and truncated (three decimal digits) after each transaction After 22 months, index fell from 1000 to 525 ─524.881, to be precise Correct value is 1098.811 ─based on underlying stocks

12 Truncation Error (3) Assume 2500 transactions a day Average error per transaction is 0.0005 Average error per day is 1.25 Assume 21 trade days a month Total estimated error is 22×21×1.25 = 577.5 Correct value is 1098.811 →Estimated wrong value = 521.311 Observed index value = 528.881

13 3. Numerical Overflow European Space Agency Ariane 5 rocket; June 4, 1996 $500 million communication satellites on board Off course and exploded 37 seconds after liftoff Overflow when 64-bit floating-point number converted to 16-bit signed integer Value measured horizontal velocity of rocket 16 bit integer sufficient for Ariane 4 Part of Ariane 4 software reused in Ariane 5

14 Divide by Zero US Navy missile cruiser USS Yorktown September 1997; off coast of Virginia A zero was entered by mistake into data field of Remote Database Manager Program A divide by zero → Database overflow → Propulsion system shut down Ship dead in water for 2 hours 45 minutes

15 5. Wrong Units of Measurement Mars Climate Orbiter; $125 million September 23, 1999 Lockheed Martin built & operated the orbiter LM engineers gave navigation commands for the Orbiter’s thruster in English units NASA use metric units Navigation information did not transfer to JPL Orbiter got to within 60km of Mars, 100 km closer than planned Orbiter’s propulsion system overheated and became disabled

16 Four Rounding Rules 1.Round to even: 1.25 → 1.2; 1.35 → 1.4; −1.35 → −1.4 2.Round toward zero (= truncate): 1.25 → 1.2; 1.35 → 1.3; −1.35 → −1.3 3.Round toward plus infinity: 1.25 → 1.3; 1.35 → 1.4; −1.35 → −1.3 4.Round toward minus infinity: 1.25 → 1.2; 1.35 → 1.3; −1.35 → −1.4

17 Important Rule on Accuracy (p. H-35) If x and y have p-bit significands, and x+y is computed exactly and then rounded to q places, a second rounding to p places will not change the answer if q ≥ 2p+2. This is true not only for addition, but also for multiplication, division, and square root.

18 IEEE Arithmetic Double precision,q=53 Single precision,p=24 So,q ≥ 2p+2 Accurate single precision can be implemented by computing in double precision, and then rounded to single precision

19 Double Rounding (p. H-34) Want to compute 1.9 × 0.66 Exact result is 1.254 Say extended precision is 3 digits Rounded to extended precision, the result is 1.25 Further rounded to single precision, the result is1.2 Correctly rounded result is 1.3, obtainable by directly rounding once What went wrong? We have:q = 3; p = 2; q < 2p+2.

20 Objective Computed result should be accurate to last bit (as if calculated in exact arithmetic, and then rounded correctly).

21 Cray-1 Computation not accurate Cray division: a/b=a × (1/b) Take b=10(Recall Patriot System). Last three bits could be wrong on Cray divides Read p. H-64 and p. H-65

22 Floating Point Operations Not Associative We have ( 3.14 + 10 10 ) −10 10 =0 But 3.14 + (10 10 −10 10 )=3.14 Also, (10 20 × 10 20 ) ×10 −20 =Overflow 10 20 × ( 10 20 ×10 −20 )=10 20

23 Euclidean Length of Vector √[ v 0 2 + v 1 2 + v 2 2 + … + v n 2 ] May overflow or underflow with v i 2, even though final result is a normal number. Try v i = 10 40, or v i = 10 −40

24 Better Way to Compute Euclidean Length Let v max = max │v i │ Thencompute v max √[ (v 0 / v max ) 2 + … + (v n / v max ) 2 ] Replace v max by an easier-to-handle quantity?


Download ppt "CSC 4250 Computer Architectures September 12, 2006 Appendix H. Computer Arithmetic."

Similar presentations


Ads by Google