Download presentation
Presentation is loading. Please wait.
1
Round-off Errors and Computer Arithmetic
Sec:1.2 Round-off Errors and Computer Arithmetic
2
Sec:1.2 Round-off Errors and Computer Arithmetic
The purpose of this section is to study how errors in numbers can propagate through mathematical functions. Why? Example: = round-off errors are directly related to the manner in which numbers are stored in a computer. * Numbers such as π, e, or cannot be expressed by a fixed number of significant figures *numbers on the computer are represented with a binary, or base-2, system. *binary system floating point numbers ⊂𝑅𝑒𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟𝑠 Error = >> format short >> pi 3.1416 >> format long relative error = =2.1𝑒−16
3
Sec:1.2 Round-off Errors and Computer Arithmetic
Binary Machine Numbers A 64-bit (binary digit) representation (floating-point number) s c f In a computer, only a relatively small subset of the real number system is used for the representation of all the real numbers. Example: 1st 11-bit 52-bit Real line −∞ +∞ ⋯ 𝟐 𝟏 𝟎 −𝟏 −𝟐 sign characteristic mantissa exponent fraction In 1985, the IEEE (Institute for Electrical and Electronic Engineers) published a report called Binary Floating Point Arithmetic Standard 754–1985. Example: This provides standards for binary and decimal floating point numbers, formats for data interchange, algorithms for rounding arithmetic operations, and for the handling of exceptions. = (−𝟏) 𝒔 𝟐 𝒄−𝟏𝟎𝟐𝟑 (𝟏+𝒇) single, double, precisions 𝒄= 1∙ ∙2 9 +⋯+ 1∙ ∙2 0 𝒄= ⋯⋯⋯+2+1 𝒄=1027
4
Sec:1.2 Round-off Errors and Computer Arithmetic
A 64-bit (binary digit) representation 11-bit exponent s c f 11-bit 52-bit sign exponent fraction 𝒄= 1∙ ∙2 9 +⋯+ 1∙ ∙2 0 Example: 𝒄= ⋯⋯⋯+2+1 𝒄=𝟏𝟎𝟐𝟕 = (−𝟏) 𝒔 𝟐 𝒄−𝟏𝟎𝟐𝟑 (𝟏+𝒇) 52-bit fraction 𝒇= 1∙( 1 2 ) 1 + 1∙( 1 2 ) 3 + 1∙( 1 2 ) 4 + 1∙( 1 2 ) 5 + 1∙( 1 2 ) 8 + 1∙( 1 2 ) 12 𝒇= =𝟎.𝟕𝟐𝟐𝟗𝟎𝟎𝟑𝟗𝟎𝟔𝟐𝟓 S = 0 c = 1027 𝑓=𝟎.𝟕𝟐𝟐𝟗𝟎𝟎𝟑𝟗𝟎𝟔𝟐𝟓 = (−𝟏) 𝒔 𝟐 𝒄−𝟏𝟎𝟐𝟑 (𝟏+𝒇) = (−𝟏) 𝟎 ×𝟐 𝟏𝟎𝟐𝟕−𝟏𝟎𝟐𝟑 × (𝟏+𝟎.𝟕𝟐𝟐𝟗𝟎𝟎𝟑𝟗𝟎𝟔𝟐𝟓) = 𝟐𝟕.𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓
5
Example: (similar to 15a/29)
Sec:1.2 Round-off Errors and Computer Arithmetic Example: (similar to 15a/29) Use the 64-bit long real format to find the decimal equivalent of the following floating-point machine number. S = 0 c = 2^9+2^8+2^7+2^6+2^5+2^4+2^3+2^2+2^1= 1022 𝒇= ( 𝟏 𝟐 ) 𝟏 + ( 𝟏 𝟐 ) 𝟒 + ( 𝟏 𝟐 ) 𝟕 + ( 𝟏 𝟐 ) 𝟖 = 𝟏 𝟐 + 𝟏 𝟏𝟔 + 𝟏 𝟏𝟐𝟖 + 𝟏 𝟐𝟓𝟔 = = (−𝟏) 𝟎 ×𝟐 𝟏𝟎𝟐𝟐−𝟏𝟎𝟐𝟑 × (𝟏+𝟎.𝟓𝟕𝟒𝟐𝟏𝟖𝟕𝟓) =𝟎.𝟕𝟖𝟕𝟏𝟎𝟗𝟑𝟕𝟓 Example: = (−𝟏) 𝟏 ×𝟐 𝟏𝟎𝟐𝟐−𝟏𝟎𝟐𝟑 × (𝟏+𝟎.𝟓𝟕𝟒𝟐𝟏𝟖𝟕𝟓) =−𝟎.𝟕𝟖𝟕𝟏𝟎𝟗𝟑𝟕𝟓
6
Largest floating point
Sec:1.2 Round-off Errors and Computer Arithmetic Largest floating point S = 0 c = 2046 𝒇=𝟏− 𝟐 −𝟓𝟐 𝒏𝒖𝒎𝒃𝒆𝒓 = (−𝟏) 𝟎 ×𝟐 𝟐𝟎𝟒𝟔−𝟏𝟎𝟐𝟑 × (𝟐− 𝟐 −𝟓𝟐 ) = e+309 >> 2^1023*(2-2^(-52)) e+308 >>2^1024-2^971 Inf Numbers greater than 𝟐 𝟏𝟎𝟐𝟑 × (𝟐− 𝟐 −𝟓𝟐 ) result in overflow (Inf)
7
smallest normalized positive number
Sec:1.2 Round-off Errors and Computer Arithmetic smallest normalized positive number S = 0 c = 1 𝒇=𝟎 𝒏𝒖𝒎𝒃𝒆𝒓 = (−𝟏) 𝟎 ×𝟐 𝟏−𝟏𝟎𝟐𝟑 × (𝟏+𝟎) = e-308 Numbers occurring in calculations that have a magnitude less than 𝟐 −𝟏𝟎𝟐𝟐 × (𝟏+𝟎) result in underflow and are generally set to zero
8
Sec:1.2 Round-off Errors and Computer Arithmetic
𝟐𝟕.𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓 𝑥 ∗ the next largest machine number any real number in the interval [𝟐𝟕.𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓, 𝟐𝟕.𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓+ 𝒙 ∗ 𝟐 ) Is represented by the real number 𝟐𝟕.𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓 𝟐𝟕.𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓+ 𝒙 ∗ 𝟐 =
9
Sec:1.2 Round-off Errors and Computer Arithmetic
Decimal Machine Numbers Binary Machine Numbers (floating-point number) we assume that machine numbers are represented in the normalized decimal floating-point form s c f Example: 5-digit decimal machine numbers ±0. 𝒅 𝟏 𝒅 𝟐 𝒅 𝟓 × 10 𝑛 , 1≤ 𝒅 𝟏 ≤ 9, 𝑎𝑛𝑑 0 ≤ 𝒅 𝒊 ≤ 9, 𝑖=2:5 Example: The floating-point form of y, denoted fl(y), is obtained by terminating the mantissa of y at k decimal digits. y = π = × two common ways of termination chopping fl(y) = × 10 1 chopping rounding fl(y) = × 10 1 rounding
10
Sec:1.2 Round-off Errors and Computer Arithmetic
Example: Example: y = π = × Determine the absolute and relative errors chopping fl(y) = × 10 1 chopping rounding fl(y) = × 10 1 rounding two methods for measuring approximation errors Remark As a measure of accuracy, the absolute error can be misleading and the relative error more meaningful, because the relative error takes into consideration the size of the value. significant digits (or figures)
11
Sec:1.2 Round-off Errors and Computer Arithmetic
significant digits (or figures) Example: Determine the significant digits 𝑝=0.1 𝑝∗= =0.0005≤5× 10 −4 Example: Determine the significant digits 𝑝=5000 𝑝∗=5002.4 = =4.8× 10 −4 ≤5× 10 −4
12
Sec:1.2 Round-off Errors and Computer Arithmetic
Finite-Digit Arithmetic Source of round-off error: number repersentations, arithmetic operations Example: ⊕, ⊖, ⊗, ⊘ represent machine addition, subtraction, multiplication, and division operations x ⊕ y = fl(fl(x) + fl(y)), Example: Suppose that x = and y = 1 3 Use five-digit chopping for calculating x + y x = fl(x) = × 10 0 y = 0. 3 fl(y) = × 10 0 x ⊕ y = fl( × × ), The number × is said to approximate to 4 significant digits = fl( × )= × 10 0
13
Sec:1.2 Round-off Errors and Computer Arithmetic
Nested Arithmetic round-off error can also be reduced by rearranging calculations Example: 𝑓 𝑥 = Evaluate f (x) at x = 4.71 using three-digit arithmetic. Exact: f (4.71)= − The relative errors Three-digit (chopping): f (4.71) = −13.5 0.05 Three-digit (rounding): f (4.71)= −13.4 0.06 𝑓 𝑥 = Three-digit (chopping): f (4.71) = −14.2 0.0045 Three-digit (rounding): f (4.71)= −14.3 0.0025 Remark The decreased error in this example is due to the reduction in computations from four multiplications and three additions to two multiplications and three additions. One way to reduce round-off error is to reduce the number of computations. Polynomials should always be expressed in nested form
14
Sec:1.2 Round-off Errors and Computer Arithmetic
rationalizing the numerator round-off error can also be reduced by rearranging calculations Example: The relative errors Remark 0.24 the subtraction of nearly equal numbers, the division by small number (x2)
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.