lecture03 - 3 Errors in computation where do they come from...

This preview shows pages 1–15. Sign up to view the full content.

# 3 Errors in computation; where do they come from? L. Olson September 1, 2015 Department of Computer Science University of Illinois at Urbana-Champaign 1

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

View Full Document
objectives look at floating point representation in its basic form expose errors of a different form: rounding error highlight IEEE-754 standard 2
why this is important: Errors come in two forms: truncation error and rounding error we always have them . . . case study: Intel our jobs as developers: reduce impact 3

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

View Full Document
example: calculating x = x + 0 . 1 4
next: floating point numbers We’re familiar with base 10 representation of numbers: 1234 = 4 × 10 0 + 3 × 10 1 + 2 × 10 2 + 1 × 10 3 and . 1234 = 1 × 10 - 1 + 2 × 10 - 2 + 3 × 10 - 3 + 4 × 10 - 4 we write 1234.1234 as an integer part and a fractional part: a 3 a 2 a 1 a 0 . b 1 b 2 b 3 b 4 For some (even simple) numbers, there may be an infinite number of digits to the right: π = 3 . 14159 . . . 1 / 9 = 0 . 11111 . . . 2 = 1 . 41421 . . . 5

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

View Full Document
other bases So far, we have just base 10. What about base β ? binary ( β = 2), octal ( β = 8), hexadecimal ( β = 16), etc In the β -system we have ( a n . . . a 2 a 1 a 0 . b 1 b 2 b 3 b 4 . . . ) β = n X k =0 a k β k + X k =0 b k β - k 6
integer conversion An algorithm to compute the base 2 representation of a base 10 integer ( N ) 10 = ( a j a j - 1 . . . a 2 a 0 ) 2 = a j · 2 j + · · · + a 1 · 2 1 + a 0 · 2 0 Compute ( N ) 10 / 2 = Q + R / 2: N 2 = a j · 2 j - 1 + · · · + a 1 · 2 0 | {z } = Q + a 0 2 |{z} = R / 2 Example Example: compute (11) 10 base 2 11 / 2 = 5 R 1 a 0 = 1 5 / 2 = 2 R 1 a 1 = 1 2 / 2 = 1 R 0 a 2 = 0 1 / 2 = 0 R 1 a 3 = 1 So (11) 10 = (1011) 2 7

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

View Full Document
the other way... Convert a base-2 number to base-10: (11 000 101) 2 = 1 × 2 7 + 1 × 2 6 + 0 × 2 5 + 0 × 2 4 + 0 × 2 3 + 1 × 2 2 + 0 × 2 1 + 1 × 2 0 = 1 + 2(0 + 2(1 + 2(0 + 2(0 + 2(0 + 2(1 + 2(1))))))) = 197 8
converting fractions straight forward way is not easy goal: for x [0 , 1] write x = 0 . b 1 b 2 b 3 b 4 · · · = X k =1 c k β - k = (0 . c 1 c 2 c 3 . . . ) β β ( x ) = ( c 1 . c 2 c 3 c 4 . . . ) β multiplication by β in base- β only shifts the radix 9

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

View Full Document
fraction algorithm An algorithm to compute the binary representation of a fraction x : x = 0 . b 1 b 2 b 3 b 4 . . . = b 1 · 2 - 1 + . . . Multiply x by 2. The integer part of 2 x is b 1 2 x = b 1 · 2 0 + b 2 · 2 - 1 + b 3 · 2 - 2 + . . . Example Example:Compute the binary representation of 0.625 2 · 0 . 625 = 1 . 25 b - 1 = 1 2 · 0 . 25 = 0 . 5 b - 2 = 0 2 · 0 . 5 = 1 . 0 b - 3 = 1 So (0 . 625) 10 = (0 . 101) 2 10
a problem with precision 1 r 0 = x 2 for k = 1 , 2 , . . . , m 3 if r k - 1 2 - k 4 b k = 1 5 r k = r k - 1 - 2 - k 6 else 7 b k = 0 8 end 9 end k 2 - k b k r k = r k - 1 - b k 2 - k 0 0.8125 1 0.5 1 0.3125 2 0.25 1 0.0625 3 0.125 0 0.0625 4 0.0625 1 0.0000 11

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

View Full Document
binary fraction example 12
a problem with precision For other numbers, such as 1 5 = 0 . 2, an infinite length is needed. 0 . 2 . 0011 0011 0011 . . . So 0.2 is stored just fine in base-10, but needs infinite number of digits in base-2 !!! This is roundoff error in its basic form... 13

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

View Full Document
numerical errors Roundoff Roundoff occurs when digits in a decimal point (0.3333...) are lost (0.3333) due to a limit on the memory available for storing one numerical value.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern