




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





CS472 1
Extra Bits for Accuracy & Rounding
CS472 2
Assume both A, B > 0 and A ≥ B ⇒ e 1 ≥ e (^2) ⇒ we need to increase e 2 to = e (^1) ⇒ shift f 2 right (e 1 ≥ e 2 ) times
case 1: e 1 = e (^2) A = 1.f 1 B = - 1.f 2 0.f 3
May have several leading zeros. Answer will be shifted left to normalize. Zeros will be inserted on the right.
CS472 3
case 2: e 1 - e 2 = 1 A = 1.f 1 1. Bnew = - 0.f 2 0. 1 b (^23) 0 < diff < 1. Bit 23 is dropped because we had to shift B right 1 place. If we had one extra bit, we could calculate the exact answer.
CS472 4
case 3: e 1 - e 2 ≥ 2 A = 1. Bnew = 0. 01 b 22 b (^23)
Bnew < 0. A - Bnew > 0.
⇒ A - Bnew = 1. or = 0. 1 ⇒ A - Bnew will only have to be shifted left at most once to normalize. We need one extra bit on the right.
CS472 7
CS472 8
X’s are number that can be represented exactly in binary 0’s are number we want to represent
X 0 X X X 0 X X 0 X X X 0 X
Always Round Up Always Round Down
CS472 9
X’s are number that can be represented exactly in binary 0’s are number we want to represent
X 0 X X X 0 X
Truncate
CS472 10
X’s are number that can be represented exactly in binary 0’s are number we want to represent
X 0 X X X 0 X X 0 X X X 0 X
X 0 X X X X depends on lsb
0 depends on lsb
CS472 13
Truncate average error. (x > 0)
x f(x) error = f(x) - x x.00 x 0 x.01 x -1/ x.10 x -1/ x.11 x -3/
average error = -3/
CS472 14
Nearest even average error. (x > 0) x f(x) error = f(x) - x x0.00 x0 0 x0.01 x0 -1/ x0.10 x0 -1/ x0.11 x1 1/ x1.00 x1 0 x1.01 x1 -1/ x1.10 x1+1 1/ x1.11 x1+1 1/
average error = 0
CS472 15
Find C = A - B. (Answer is negative because A<0, -B<0) Use the 3 extra bits: Guard, Round, and Sticky. Round to nearest even. A =
S exp fraction 1 1000 0100 0000 1111 1111 1111 1111 111 B =
S exp fraction 0 1000 0000 1111 1111 1111 1111 1111 101
e = 5 e = 1 A = 1.0000 1111 1111 1111 1111 111 0 0 0 Bn = 0.0001 1111 1111 1111 1111 111 1 1 1 Sum = 1.0010 1111 1111 1111 1111 110 1 1 1 normalized 1.0010 1111 1111 1111 1111 111 round up
G R S
CS472 16
Let p = proper number of significant bits in the significand Sump is the least significant bit in the significand A blank box means that the p most significant bits in the significand are correctly rounded If a formula evaluates to true, add 1 Sump Else, add 0 to Sump Rounding Mode Sum ≥ 0 Sum< Round Down g+r+s Round Up g+r+s Truncate Nearest Even g(r+s+Sum (^) p) g(r+s+Sum (^) p )