Carnegie Mellon Instructors:**Randy&Bryant&&&Dave&O’Hallaron&Floa.ng*Point&155213:&Introduc<on&to&Computer&Systems&3rd&&Lecture,&Aug.&31,&2010&2!Carnegie Mellon!Today:*Floa.ng*Point* Background:&Frac<onal&binary&numbers& IEEE&floa<ng&point&standard:&Defini<on& Example&and&proper<es& Rounding,&addi<on,&mul<plica<on& Floa<ng&point&in&C& Summary&3!Carnegie Mellon!Frac.onal*binary*numbers* What&is&1011.1012?&4!2i&2i51&4&2&1&1/2&1/4&1/8&25j&bi&bi51&•••& b2&b1&b0&b51&b52&b53&•••& b5j&Carnegie Mellon!• • •!Frac.onal*Binary*Numbers* Representa<on& Bits&to&right&of&“b inary&poi nt” &represent&frac<onal&po wers&of&2& Represents&ra<onal&number:&• • •!5!Carnegie Mellon!Frac.onal*Binary*Numbers:*Examples* Value &Representa<on&!5 3/4 !101.112& !2 7/8 !010.1112& !63/64 !001.01112& Observa<ons& Divide&by&2&by&shi]ing&right& Mul<ply&by&2&by&shi]ing&le]& Numbers&of&form&0.111111…2&are&just&below&1.0& 1/2&+&1/4&+&1/8&+&…&+&1/2i&+&…&➙&1.0& Use¬a<on&1.0&–&ε&6!Carnegie Mellon!Representable*Numbers* Limita<on& Can&only&exactly&represent&numbers&of&the&form&x/2k& Other&ra<onal&numbers&have&repea<ng&bit&representa<ons& Value &Representa<on& 1/3 &0.0101010101[01]…2! 1/5 &0.001100110011[0011]…2! 1/10 &0.0001100110011[0011]…2!7!Carnegie Mellon!Today:*Floa.ng*Point* Background:&Frac<onal&binary&numbers& IEEE&floa<ng&point&standard:&Defini<on& Example&and&proper<es& Rounding,&addi<on,&mul<plica<on& Floa<ng&point&in&C& Summary&8!Carnegie Mellon!IEEE*Floa.ng*Point* IEEE&Standard&754& Established&i n&1985&as&uni form&stand ard&for&flo a<ng&po in t&arithme<c& Before&that,&many&idiosyncra<c&formats& Supported&by&all &major&CPUs& Driven&by&numerical&concerns& Nice&standards&for&roundin g,&overflow,&underflow& Hard&to&make&fast&in&hardware& Numerical&analysts&predominated&over&hardware&designers&in&defining&standard&9!Carnegie Mellon! Numerical&Form:&&& &&(–1)s&M&&2E& Sign&bit&s&determines&whether&number&is&nega<ve&or&posi<ve& Significand&M&& normall y&a&frac<onal& value&in &range&[1.0,2.0).& Exponent&E&weights&value&by&power&of&two& Encoding& MSB&s&is&sign&bi t&s& exp&field&encodes&E&(but&is¬& equal& to&E)& frac&field&encodes&M&(but&is¬&equ al&to &M)&Floa.ng*Point*Representa.on*s!exp! frac!10!Carnegie Mellon!Precisions* Single&precision:&32&bits& Double&precision:&64&bits& Extended&precision:&80&bits&(Intel&only)&s!exp! frac!1! 8-bits! 23-bits!s!exp! frac!1! 11-bits! 52-bits!s!exp! frac!1! 15-bits! 63 or 64-bits!11!Carnegie Mellon!Normalized*Values* Condi<on:&exp&≠&000…0&and&exp&≠&111…1& Exponent&coded&as&biased&value:&E&&=&&Exp&–&Bias& Exp:&unsigned&value&exp&& Bias&=&2k51&5&1,&where&k&is&number&of&exponent&bits& Single&precision:&127&(Exp:&1…254,&E:&5126…127)& Double&precision:&1023&(Exp:&1…2046,&E:&51022…1023)& Significand&coded&with&implied&leading&1:&M&&=&&1.xxx…x2& &xxx…x:&bits&of&frac& Minimum&when&000…0&(M&=&1.0)& Maximum&when&111…1&(M&=&2.0&–&ε)& Get&extra&leading&bit&for&“free”&Carnegie Mellon 12!Normalized*Encoding*Example* Value:*Float F = 15213.0;* 1521310&&=&111011011011012&&&&&&&&&&&&&&&&&&&&&&&&&=&1.11011011011012&x&213& Significand*M& &=& &1.11011011011012 frac = 110110110110100000000002* Exponent*E #& &=& &13&Bias& &=& &127&Exp& &=& &140& &= &100011002 Result:*0 10001100 11011011011010000000000 s exp frac13!Carnegie Mellon!Denormalized*Values* Condi<on:&exp = 000…0& Exponent&value:&E&=&–Bias&+&1&(instead&of&E&=&0&–&Bias)& Significand&coded&with&implied&leading&0:&M&=&0.xxx…x2& xxx…x:&bits&o f&frac& Cases& &exp&=&000…0,&frac&=&000…0& Represents&zero&value& Note&dis<nct&values:&+0&and&–0&(why?)& exp&=&000…0,&frac&≠&000…0& Numbers&very&close&to&0.0& Lose&precision&as&get&smaller& Equispaced&14!Carnegie Mellon!Special*Values* Condi<on:&exp&=&111…1& Case:&exp&=&111…1,&frac&=&000…0& Represents&value&∞&(infinity)& Opera<on&that&overflows& Both&posi<ve&and&n ega<ve& E.g.,&1.0/0.0&=&−1.0/−0.0&=&+∞,&&1.0/−0.0&=&−∞& Case:&exp&=&111…1,&frac&≠&000…0& Not5a5Number&(NaN)& Represents&case&when&no&numeric&value&can&be&determined& E.g.,&sqrt(–1),&∞&−&∞,&∞&×&0&15!Carnegie Mellon!Visualiza.on:*Floa.ng*Point*Encodings*+∞&−∞&50&+Denorm& +Normalized&−Denorm&−Normalized&+0&NaN&NaN&16!Carnegie Mellon!Today:*Floa.ng*Point* Background:&Frac<onal&binary&numbers& IEEE&floa<ng&point&standard:&Defini<on& Example&and&proper<es& Rounding,&addi<on,&mul<plica<on& Floa<ng&point&in&C& Summary&17!Carnegie Mellon!Tiny*Floa.ng*Point*Example* 85bit&Floa<ng&Point&Representa<on& the&sign&bit&is&i n&th e&most&signi fican t&bi t& the&next&four&bits&are&the&exponent,&with&a&b ias& of&7& the&last&three&bits&are&the&frac& Same&general&form&as&IEEE&Format& normalized,&denormalized& representa<on&of&0,&NaN,&infinity&s! exp! frac!1! 4-bits! 3-bits!18!Carnegie Mellon!s exp frac E Value 0 0000 000 -6 0 0 0000 001 -6 1/8*1/64 = 1/512 0 0000 010 -6 2/8*1/64 = 2/512 … 0 0000 110 -6 6/8*1/64 = 6/512 0 0000 111 -6 7/8*1/64 = 7/512 0 0001 000 -6 8/8*1/64 = 8/512 0 0001 001 -6 9/8*1/64 = 9/512 … 0 0110 110 -1 14/8*1/2 = 14/16 0 0110 111 -1 15/8*1/2 = 15/16 0 0111 000 0 8/8*1 = 1 0 0111 001 0 9/8*1 = 9/8 0 0111 010 0 10/8*1 = 10/8 … 0 1110 110 7 14/8*128 = 224 0 1110 111 7 15/8*128 = 240 0 1111 000 n/a inf Dynamic*Range*(Posi.ve*Only)*closest*to*zero*largest*denorm*smallest*norm*closest*to*1*below*closest*to*1*above*largest*norm*Denormalized*numbers*Normalized*numbers*19!Carnegie Mellon!Distribu.on*of*Values* 65bit&IEEE5like&format& e&=&3&exponent&bits& f&=&2&frac<on&bits& Bias&is&235151&=&3& No<ce&how&the&distribu<on&gets&denser&toward&zero.&&&8&values&s! exp! frac!1! 3-bits! 2-bits!20!Carnegie Mellon!Distribu.on*of*Values*(closeJup*view)* 65bit&IEEE5like&format& e&=&3&exponent&bits&
View Full Document