CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Winter 2004 Lecture 9
CSE 2462 Topics: Floating Point Numbers (IEEE P754) Standard Operations Exceptional Situations Rounding Modes
CSE 2463 Standard 2 32 Typically Goal: Dynamic Range: largest #/ smallest # If too large, holes between # ’ s
CSE 2464 Standard ulp (unit in the last place) Difference between two consecutive values of the significand. 3 Parts x = s b e Sign Bit 8-bit exponent Significand
CSE 2465 Standard a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 b 1 b 2 b 3 b 22 b 23 1.* normalized number 0.* denormalized number 0 0.b 1 b 2 b 3 b 22 b 23 b 1 b 2 b 3 b 22 b 23 b 1 b 2 b 3 b 22 b 23 if b i = 0 for all i = 1,2, …,23, NaN otherwise NaN Not a Number
CSE 2466 Standard 0.01x2 -3 = 0.00x2 -2 Same number, so normalize to remove redundancy Smallest Number 0.00 … 01x = 1.0x2 -23 x = 1x Difference between 2 # ’ s small for normalized times compared to magnitudes
CSE 2467 Standard - Example s. eeeeeeee nnnnnnnnnnnnnnnnnnnnnnn = … 0x = = … 0x minimal normalized # = … 1x = … 1x = … 0x2 1
CSE 2468 Standard – Example Cont = … 1x = … 1x Normalized Maximum = N min = 1.0 x N max = (2 – )2 127
CSE 2469 Double Floating Point a 1 a 2 … a 11 b 1 b 2 … b … b 1 b 2 … b 52 x … b 1 b 2 … b 52 x … b 1 b 2 … b 52 x … b 1 b 2 … b 52 x … b 1 b 2 … b 52 x … 11 = if b i = 0 for all i = 1,2, …,52
CSE Overflow/Underflow N max N min SparserDenser Overflow Underflow
CSE Addition/Multiplication s 1 xb e1 + ( s 2 xb e2 ) = sxb e = s 1 xb e1 + s 2 /b e1-e2 x b e1 = ( s 1 s 2 /b e1-e2 ) x b e1 ( s 1 xb e1 ) x ( s 2 xb e2 ) = (s 1 xs 2 )b e1+e2
CSE Exceptions a/0 = if a > 0 a/ = 0if a != 0 a · 0 = 0 a · = if a > 0 0 · = invalid operation (NaN) 0/0 = invalid operation (NaN) NaP op a = NaN a + = - = NaN
CSE Rounding Mode Adder Output = Cout z 1 z 0.z -1 z -2 … z - l GRS Guard Bit Round Bit Sticky Bit, OR of all bits below bit R x x x x2 4 Normalize – need to round or
CSE Rouding x x x x 2 0 normalize x x x x x x 2 2 Guard bit
CSE Rounding Round to the nearest even toward Toward + Toward -
CSE Conventional Rounding Error Rounding Error 1.101= 1.101= = = Average Error = 0.5/4 = 0.125