CSC_349_HANDOUT#4 - COMPUTER SCIENCE 349A Handout Number 4...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 COMPUTER SCIENCE 349A Handout Number 4 SUBTRACTIVE CANCELLATION (pages 68-72 of the 5 th edition; pages 73-76 of the 6 th edition) Subtractive cancellation refers to the loss of significant digits during a floating- point computation due to the subtraction of nearly equal floating-point numbers. Note that if x ˆ is an approximation to 0 > x and y ˆ is an approximation to 0 > y , and if for example x ˆ agrees with x to 8 significant digits and y ˆ agrees with y to 8 significant digits, then × y x ˆ ˆ y x × y x y x / ˆ / ˆ y x y x + + ˆ ˆ and these values will agree to about 8 significant digits. However, this may not be true for subtraction: it is possible that none of the significant digits in y x ˆ ˆ and y x agree. The following examples illustrate subtractive cancellation, and show how it can be avoided in each of these cases. Example 1. The evaluation of ( ) x x f + 1 2 l will be inaccurate if x is large and positive. For example, using 10 = b , 4 = k , idealized rounding floating-point arithmetic and x = 65.43, we obtain the following (where ( ) z f l is computed using idealized floating-point arithmetic; that is, the exact value of z is rounded to 4 significant digits). ( ) () () () ( ) () () ( ) () 1 2 2 2 4 2 10 1000 . 0 or 01 . 0 43 . 65 44 . 65 1 44 . 65 43699 . 65 4282 1 4282 1 4281 1 10 4281 . 0 or 4281 0849 . 4281 × = = + = = = + = + = + × = = l l L l l l l l l l f x x f f f x f f x f f x f However, the true (exact) value of x x + 1 2 is L 0076413 . 0 . The relative error in ( ) x x f + 1 2 l is about 0.31 or 31%. To avoid the subtractive cancellation above and to obtain an accurate floating- point result, note that
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 ( ) x x x x x x x x + + = + + + + + 1 1 1 1 1 2 2 2 2 . The latter expression gives an extremely accurate result in floating-point arithmetic when
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/10/2011 for the course CSC 349 taught by Professor Oadje during the Spring '11 term at University of Victoria.

Page1 / 5

CSC_349_HANDOUT#4 - COMPUTER SCIENCE 349A Handout Number 4...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online