1.2 Round-off Errors and Computer Arithmetic 1 IEEE floating point numbers β’ Binary number: (β¦ π3 π2 π1 π0 . πβ1 πβ2 πβ3 β¦ )2 β’ Binary to decimal: (β¦ π3 π2 π1 π0 . πβ1 πβ2 πβ3 β¦ )2 = (β¦ π3 23 +π 2 22 + π1 21 + π0 20 + πβ1 2β1 + πβ2 2β2 + πβ3 2β3 β¦ )10 β’ Double precision (long real) format β Example: βdoubleβ in C β’ A 64-bit (binary digit) representation β 1 sign bit (s), 11 exponent bits β characteristic (c), 52 binary fraction bits β mantissa (f) Represented number: β1 π 2πβ1023 (1 + π) 1023 is called exponent bias 2 β’ β’ β’ β’ β’ 0 β€ πβπππππ‘ππππ π‘ππ π β€ 211 β 1 = 2047 Smallest normalized positive number on machine has π = 0, π = 1, π = 0: 2β1022 β (1 + 0) β 0.22251 × 10β307 Largest normalized positive number on machine has π = 0, π = 2046, π = 1 β 2β52 : 21023 β (1 + 1 β 2β52 ) β 0.17977 × 10309 Underflow: ππ’πππππ < 2β1022 β (1 + 0) Overflow: ππ’πππππ > 21023 β (2 β 2β52 ) Machine epsilon ππππβ = 2β52 : this is the difference between 1 and the smallest machine floating point number greater than 1. 3 Decimal machine numbers β’ k-digit decimal machine numbers: ±0. π1 π2 β¦ ππ × 10π , 1 β€ π1 β€ 9, 0 β€ ππ β€ 9 β’ Any positive number within the numerical range of machine can be written: π¦ = 0. π1 π2 β¦ ππ ππ+1 ππ+2 β¦ × 10π Chopping and Rounding Arithmetic: Step 1: represent a positive number π¦ by 0. π1 π2 β¦ ππ ππ+1 ππ+2 β¦ × 10π Step 2: β Chopping: chop off after π digits: ππ π¦ = 0. π1 π2 β¦ ππ × 10π 4 β Rounding: add (5 × 10β chopping π+1 ) × 10π to π¦, then a) If ππ+1 β₯ 5, add 1 to ππ to get ππ π¦ b) If ππ+1 < 5, simply do chopping Errors and significant digits 5 Finite-digit arithmetic β’ Catastrophic events a) Subtracting nearly equal numbers β this leads to fewer significant digits. b) Dividing by a number with small magnitude (or multiplying by a number with large magnitude). 6 Avoiding loss of accuracy by reformulating calculations Quadratic formula to find roots of ππ₯ 2 + ππ₯ + π = 0, π€βπππ π β 0. 1. π₯1 = 2. π₯2 = βπ+ π2 β4ππ 2π βπβ π2 β4ππ 2π Key: Magnitudes of π πππ π 2 β 4ππ decide whether we need to reformulate the formula. 7
© Copyright 2026 Paperzz