Lec05_FloatingPointError_2per

Lec05_FloatingPointError_2per - 1 EECS EECS EECS EECS EECS...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 EECS285 Lecture 05 Floating Point Arithmetic Van der Linden Ch. 7 EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 2 Andrew M. Morgan Floating Point Error • What is the result of the expression (1.0 / 3.0)? – 0.33 is close, but not quite – 0.33333 is closer, but still… • Consider the way a floating point value is stored in memory – Floats use 4 bytes (32 bits) – Doubles use 8 bytes (64 bits) • If there were a data type to store numbers between 0 and 1 that used only 4 bits, here are the values that could be stored 0000 = .0 1000 = .5 0001 = .0625 1001 = .5625 0010 = .125 1010 = .625 0011 = .1875 1011 = .6875 0100 = .25 1100 = .75 0101 = .3125 1101 = .8125 0110 = .375 1110 = .875 0111 = .4375 1111 = .9375 2 EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 3 Andrew M. Morgan Floating Point Error, Cot'd • To store (1.0 / 3.0) using the 4 bit data type, we would choose either 0101 or 0110 • Say we chose 0101 to use 0.3125 as an approximation to 0.3333 – 1.0 – (1.0/3.0) – (1.0/3.0) – (1.0/3.0) = 1.0 – 0.3125 – 0.3125 – 0.3125 = 0.0625 • If we use more bits, we can get closer to 0, we'll never get exactly...
View Full Document

This note was uploaded on 01/19/2012 for the course EECS 285 taught by Professor Idk during the Fall '08 term at University of Michigan.

Page1 / 4

Lec05_FloatingPointError_2per - 1 EECS EECS EECS EECS EECS...

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