ppt 02-3-float_第1页
ppt 02-3-float_第2页
ppt 02-3-float_第3页
ppt 02-3-float_第4页
ppt 02-3-float_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、,Today: Floating Point,Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties Rounding, addition, multiplication Floating point in C,Fractional binary numbers,What is 1011.1012?, ,Fractional Binary Numbers,Representation Bits to right of “binary point”

2、represent fractional powers of 2 Represents rational number:, ,Fractional Binary Numbers: Examples,ValueRepresentation 5 3 4 101.112 2 7 8 010.1112 1 15 16 001.11112 Observations Divide by 2 by shifting right Multiply by 2 by shifting left Numbers of form 0.1111112 are just below 1.0 1/2 + 1/4 + 1/8

3、 + + 1/2i + 1.0 Use notation 1.0 ,Representable Numbers,Limitation Can only exactly represent numbers of the form x/2k Other rational numbers have repeating bit representations ValueRepresentation 1/30.0101010101012 1/50.00110011001100112 1/100.000110011001100112,Today: Floating Point,Background: Fr

4、actional binary numbers IEEE floating point standard: Definition Example and properties Rounding, addition, multiplication Floating point in C,IEEE Floating Point,A floating-point representation Encodes rational numbers of the form V = x 2y Useful for: very large numbers (|V| 0) 234 numbers very clo

5、se to 0 (|V| 1) 2-34 more generally as an approximation to real arithmetic Hard to make fast in hardware IEEE Standard 754 Established in 1985 as uniform standard for floating point arithmetic Before that, many idiosyncratic formats Supported by all major CPUs,Numerical Form: (1)s M 2E Sign bit s de

6、termines whether number is negative or positive Significand M normally a fractional value in range 1.0,2.0). Exponent E weights value by power of two Encoding MSB s is sign bit s exp field encodes E (but is not equal to E) frac field encodes M (but is not equal to M),Floating Point Representation,Pr

7、ecisions,Single precision: 32 bits Double precision: 64 bits Extended precision: 80 bits (Intel only),Categories of single-precision, floating-point values,Normalized Values,Condition: exp 0000 and exp 1111 Value: (1)s M 2E Exponent coded as biased value: E = Exp Bias Exp: unsigned value exp Bias =

8、2k-1 - 1, where k is number of exponent bits Single precision: 127 (Exp: 1 254, E: -126 127) Double precision: 1023 (Exp: 1 2046, E: -1022 1023) Significand coded with implied leading 1: M = 1.xxxx2 xxxx: bits of frac Minimum when 0000 (M = 1.0) Maximum when 1111 (M = 2.0 ) Get extra leading bit for

9、 “free”,Normalized Encoding Example,Value: Float F = 15213.0; 1521310 = 11 1011 0110 11012 ( 14 bits ) = 1.11011011011012 x 213 Significand M = 1.11011011011012 frac= 110110110110100000000002 Exponent E = 13 Bias = 127 Exp = E + Bias = 140 = 100011002 Result:,s,exp,frac,0 10001100 110110110110100000

10、00000,E = Exp Bias,Denormalized Values,Condition: exp = 0000 Value: (1)s M 2E Exponent value: E = 1Bias (instead of E = 0 Bias) Significand coded with implied leading 0: M = 0.xxxx2 xxxx: bits of frac Cases exp = 0000, frac = 0000 Represents zero value Note distinct values: +0 and 0 exp = 0000, frac

11、 0000 Numbers very close to 0.0 Equispaced,Special Values,Condition: exp = 1111 Case: exp = 1111, frac = 0000 Represents value (infinity) Operation that overflows Both positive and negative E.g., 1.0/0.0 = 1.0/0.0 = +, 1.0/0.0 = Case: exp = 1111, frac 0000 Not-a-Number (NaN) Represents case when no

12、numeric value can be determined E.g., sqrt(1), , 0,Visualization: Floating Point Encodings,+,0,+Denorm,+Normalized,Denorm,Normalized,+0,NaN,NaN,Today: Floating Point,Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties Rounding, addition, multiplicati

13、on Floating point in C,Distribution of Values,6-bit IEEE-like format e = 3 exponent bits f = 2 fraction bits Bias = 23-1-1 = 3 Notice how the distribution gets denser toward zero.,8 values,Distribution of Values (close-up view),6-bit IEEE-like format e = 3 exponent bits f = 2 fraction bits Bias is 3

14、,Tiny Floating Point Example,8-bit Floating Point Representation the sign bit is in the most significant bit the next four bits are the exponent, k=4 Bias = 2k-1 1 = 7 the last three bits are the frac, n=3 Same general form as IEEE Format normalized, denormalized, special representation of 0, infini

15、ty, NaN,s exp fracEValue 0 0000 000-60 0 0000 001-61/8*1/64 = 1/512 0 0000 010-62/8*1/64 = 2/512 0 0000 110-66/8*1/64 = 6/512 0 0000 111-67/8*1/64 = 7/512 0 0001 000-68/8*1/64 = 8/512 0 0001 001 -69/8*1/64 = 9/512 0 0110 110-114/8*1/2 = 14/16 0 0110 111-115/8*1/2 = 15/16 0 0111 00008/8*1 = 1 0 0111

16、00109/8*1 = 9/8 0 0111 010010/8*1 = 10/8 0 1110 110714/8*128 = 224 0 1110 111715/8*128 = 240 0 1111 000n/ainf 0 1111 xxxn/a NaN,Dynamic Range (Positive Only),closest to zero,largest denorm,smallest norm,closest to 1 below,closest to 1 above,largest norm,Denormalized numbers,Normalized numbers,Intere

17、sting Numbers,DescriptionexpfracNumeric Value Zero000000000.0 Smallest Pos. Denorm.000000012 23,52 x 2 126,1022 Single 1.4 x 1045 Double 4.9 x 10324 Largest Denormalized00001111(1.0 ) x 2 126,1022 Single 1.18 x 1038 Double 2.2 x 10308 Smallest Pos. Normalized000100001.0 x 2 126,1022 Just larger than

18、 largest denormalized One011100001.0 x 20 Largest Normalized11101111(2.0 ) x 2127,1023 Single 3.4 x 1038 Double 1.8 x 10308,single,double,underflow,overflow,Special Properties of Encoding,FP Zero Same as Integer Zero All bits = 0 Can (Almost) Use Unsigned Integer Comparison Must first compare sign b

19、its Must consider 0 = 0 NaNs problematic Will be greater than any other values Otherwise OK Denorm vs. normalized Normalized vs. infinity,Today: Floating Point,Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties Rounding, addition, multiplication Flo

20、ating point in C,Floating Point Operations: Basic Idea,x + fy = Round(x + y) x fy = Round(x y) Basic idea First compute exact result Make it fit into desired precision Possibly overflow if exponent too large Possibly round to fit into frac,Rounding,Rounding Modes (illustrate with $ rounding) 1.401.6

21、01.502.501.50 Towards zero11121 Round down ()11122 Round up (+) 22231 Nearest Even (default)12222 What are the advantages of the modes?,Closer Look at Round-To-Even,Default Rounding Mode All others are statistically biased Sum of set of positive numbers will consistently be over- or under- estimated

22、 Applying to Other Decimal Places / Bit Positions When exactly halfway between two possible values Round so that least significant digit is even E.g., round to nearest hundredth 1.23499991.23(Less than half way) 1.23500011.24(Greater than half way) 1.23500001.24(Half wayround up) 1.24500001.24(Half wayround down),Rounding Binary Numbers,Binary Fractional Numbers “Even” when least significant

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论