




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、数据的表示计算机硬件能够直接识别的数据类型,如定点数、浮点数等硬件直接识别:意味着某种数据类型可用计算机硬件直接表示出来,并能由计算机指令直接调用该种数据类型。比如,数组、结构这一类数据,由于计算机不能一次对它进行存取、也不能一次处理它,它要分多次处理,所以它并不是计算机能够直接表示的数据。1.5 计算机中数据的表示Floating-PoNumbersIEEE 754 Floating-PoStandardFloating-PoAddition1.5.3 小数表示Floating PoThe World is Not JustegersProgramming languagepport num
2、bers with fractionCalled floating-ponumbersExles:3.14159265 ()2.71828 (e)0.000000001 or 1.0 109 (seconds in a nanosecond)86,400,000,000,000 or 8.64 1013 (nanoseconds in a day)last number is a largeegert cannot fit in a 32-bitegerWe use a scientific noion (科学记数法) to representFloating PoVery small num
3、bers (e.g. 1.0 109)Very large numbers (e.g. 8.64 1013)Scientific noion: d . f1f2f3f4 10Digital System II e1e2e3slide 4ExExles of floating-ponumbers in base 10 5.341103 , 0.05341105 , 2.013101 , 201.3103decimal poles of floating-ponumbers in base 2 1.00101223 , 0.0100101225 , 1.10110123 , 1101.10126b
4、inary poExponents(指数) are kept in decimal for clarityThe binary number (1101.101)2 = 23+22+20+21+23 = 13.625Floating-ponumbers should be normalized(规格化)Exactly one non-zero digit should appear before the poIn a decimal number, this digit can be from 1 to 9In a binary number, this digit should be 1No
5、rmalized FP Numbers: 5.341103and 1.10110123NOT Normalized: 0.05341105 and 1101.10126Floating PoDigital System IIslide 5Floating-PoNumbersFloating-PoRepresenionA floating-ponumber is represented by the triple(三部分)S is the Sign bit (0 isitive and 1 is negative)Represenion is called sign and magnitudeE
6、 is the Exponent field (signed)Very large numbers have largeitive exponentsVery small close-to-zero numbers have negative exponentsMore bits in exponent field increases range of valuesF is the Fraction field (fraction after binary poMore bits in fraction field improves the preci)of FP numbersFloatin
7、g PoDigital System IIslide 6Value of a floating-ponumber = (-1)S val(F) 2val(E)SExponentFractionNext . . .Floating-PoNumbersIEEE 754 Floating-PoStandardFloating-PoAdditionFloating PoDigital System IIslide 7Found in virtually every computer invented since 1980Simplified porting (移植)of floating-ponumb
8、ersUnified() the development of floating-poalgorithmsnumbersIncreased the accuracy(准确性) of floating-poSingle PreciFloating PoNumbers (32 bits)1-bit sign + 8-bit exponent + 23-bit fractionDouble PreciFloating PoNumbers (64 bits)1-bit sign + 11-bit exponent + 52-bit fractionFloating PoDigital System I
9、Islide 8优点SExponent11Fraction52(continued)SExponent8Fraction23IEEE 754 Floating-PoStandardFor a normalized floating ponumber (S, E, F)Significand(尾数) is equal to (1.F)2 = (1.f1f2f3f4)2IEEE 754 ames hidden 1. (not stored) for normalized numbersSignificand is 1 bit longern fraction(有效位数比实际的长了1位)Value
10、of a Normalized Floating PoNumber is)(1)S is 1 when S is 0 (Floating Poitive), and 1 when S is 1 (negative)Digital System IIslide 9转换(1)S (1.F)2 2val(E)(1)S (1.f1f2f3f4 )2 2val(E)(1)S (1 + f12-1 + f22-2 + f32-3 + f42-4 )2 2val(ESEF = f1 f2 f3 f4 Normalized Floating PoNumbersFor a normalized floating
11、 ponumber (S, E, F)用 原码 表示用 移码 表示符号位:0 +1 -Floating PoDigital System IIslide 10SEF = f1 f2 f3 f4 Normalized Floating PoNumbersBiased Exponent RepresenionHow to represent a signed exponent? Choiare Sign + magnitude represenion for the exponent(符号+幅值)Twos complement represenion(补码)Biased represenion(移
12、码)IEEE 754 uses biased represenion for the exponentValue of exponent = val(E) = E Bias (Bias is a constant)Recallt exponent field is 8 bits for single preciE can behe range 0 to 255E = 0 and E = 255 are (discussed later)(保留) for spel useE = 1 to 254 are used for normalized floating poBias = 127 (hal
13、f of 254), val(E) = E 127numbersval(E=1) = 126, val(E=127) = 0, val(E=254) = 127Floating PoDigital System IIslide 11 Biased Exponent(移码) ContdFor double preci, exponent field is 11 bitsE can behe range 0 to 2047E = 0 and E = 2047 arefor spel useE = 1 to 2046 are used for normalized floating poBias =
14、 1023 (half of 2046), val(E) = E 1023numbersval(E=1) = 1022, val(E=1023) = 0, val(E=2046) = 1023Value of a Normalized Floating PoNumber isFloating PoDigital System IIslide 12转换(1)S (1.F)2 2E Bias(1)S (1.f1f2f3f4 )2 2E Bias(1)S (1 + f12-1 + f22-2 + f32-3 + f42-4 )2 2E BiasExles of Single PreciFloatWh
15、at is the decimal value of this Single Precifloat?Solution:Sign = 1 is negativeExponent = (01111100)2 = 124, E bias = 124 127 = 3Significand = (1.0100 0)2 = 1 + 2-2 = 1.25 (1. is implicit)Value in decimal = 1.25 23 = 0.15625What is the decimal value of?Solution:implicitValue in decimal = +(1.0100110
16、0 0)2 2130127=(1.01001100 0)2 23 = (1010.01100 0)2 =Digital System II10.375Floating Poslide 130100000100100110000000000000000010111110001000000000000000000000Exles of Double PreciFloatWhat is the decimal value of this Double Precifloat ?Solution:Value of exponent = (10000000101)2 Bias = 1029 1023 =
17、6Value of double float = (1.00101010 0)2 (1001010.10 0)2 = 74.5What is the decimal value of ? 26(1. is implicit) =t yourself! (answer should be 1.5 27Digital System IIFloating Po= 0.01171875)slide 1410111111100010000000000000000000000000000000000000000000000000000100000001010010101000000000000000000
18、000000000000000000000000000Converting FP Decimal to BinaryConvert 0.8125 to binary in single and double preciSolution:Fraction bits can be obtained using multiplication by 20.8125 2 = 1.6250.625 20.25 2 0.5 2= 1.25= 0.5= 1.0Stop when fractional part is 0Fraction = (0.1101)2 = (1.101)2 2 1(Normalized
19、)Exponent = 1 + Bias = 126 (single preci) and 1022 (double)Single PreciDouble PreciFloating PoDigital System IIslide 151011111111101010000000000000000000000000000000000000000000000000101000000000000000000000.8125 = (0.1101)2 = + + 1/16 = 13/Largest Normalized FloatWhat is the Largest normalized floa
20、t?Solution for Single Preci:Exponent bias = 254 127 = 127 (largest exponent for SP)Significand = (1.111 1)2 = almost 2Value in decimal 2 2127 2128: 3.4028 1038Solution for Double PreciValue in decimal 2 21023 21024 1.79769 10308Overflow: exponent is too large to fithe exponent fieldslide 16Floating
21、PoDigital System II011111111110111111111111111111111111111111111111111111111111111101111111011111111111111111111111Smallest Normalized FloatWhat is the smallest (in absolute value) normalized float?Solution for Single Preci:Exponent bias = 1 127 = 126 (smallest exponent for SP)Significand = (1.000 0
22、)2 = 1Value in decimal = 1 2126 = 1.17549 1038Solution for Double Preci:Value in decimal = 1 21022 = 2.22507 10308Underflow: exponent is too small to fit in exponent fieldFloating PoDigital System IIslide 17000000000001000000000000000000000000000000000000000000000000000000000000100000000000000000000
23、000Zero, Infinity, and NaNZeroExponent field E = 0 and fraction F = 0 +0 and 0 areInfinitysible according to sign bit SInfinity is a speFor single preciFor double precil value represented withwith 8-bit exponent: with 11-bit exponent:um E and F = 0um E = 255 um E = 2047by zeroInfinity can result fro
24、m overflow or divi+ and aresible according to sign bit SNaN (Not a Number)Floating PoNaN is a spel value represented withum E and F 0Result from exceptional situations, such as 0/0 or sqrt(negative)Operation on a NaN results is NaN: Op(X, NaN) = NaNDigital System IIslide 18 Denormalized(非规格化) Number
25、s IEEE standard uses denormalized numbers to Fill the gap betProvide graduan 0 and the smallest normalized floatderflow to zeroDenormalized: exponent field E is 0 and fraction F 0Implicit 1. before the fraction nowes 0. (not normalized)Value of denormalized number ( S, 0, F )NegativeOverflowNegative
26、UnderflowitiveitiveUnderflowOverflow-+DenormDenormNormalized (+ve)0Digital System II-2128Floating Po-212621262128slide 19Normalized (ve)Single preci:(1) S (0.F)2 2126 Double preci:(1) S (0.F)2 21022Summary of IEEE 754 EncodingFloating PoDigital System IIslide 20Double-PreciExponent = 11Fraction = 52
27、ValueNormalized Number1 to 2046Anything (1.F)2 2E 1023Denormalized Number0nonzero (0.F)2 21022Zero00 0Infinity20470 NaN2047nonzeroNaNSingle-PreciExponent = 8Fraction = 23ValueNormalized Number1 to 254Anything (1.F)2 2E 127Denormalized Number0nonzero (0.F)2 2126Zero00 0Infinity2550 NaN255nonzeroNaNCo
28、nsider Adding (Single-PreciFloating-Po):+1.1.0001020010122422Cannot add significands Why?Because exponents are not equalHow to make exponents equal?Shift the significand of the lesser exponent rightDifference betn the two exponents = 4 2 = 2So, shift right second number by 2 bits and increment expon
29、ent1.00101222=0.00001Digital System II01224Floating Poslide 21Floating PoAddition ExleNow, ADD the Significands:+1.1.000100010124221.0.000010000101 2424(shift right)(result)01 24+10.0Addition produ0011a carry bit, result is NOT normalizedNormalize Result (shift right and increment exponent):2425+10.
30、01.00001100101101=Floating PoDigital System IIslide 22Floating-PoAddition contd8位二进制数,可以代表不同的值小结:计算机有符号数de 23“Father” of the IEEE 754 standard直到80年代初,各个机器的浮点数表示格式还没有,因而相互不兼容,机器之间传送数据时,带来麻烦1970年代后期, IEEE成立着手制定浮点数标准1985年完成浮点数标准IEEE754的制定现在所有计算机都采用IEEE754来表示浮点数This standard was primarily the work of on
31、e UC Berkeley math professor William Kahan.,/wkahan/ us/754story.htmlDigital System IIieee754sFloating PoProf. William Kahanslide 2(2) IEEE 754格式单精度双精度指数采用偏移值,其中单精度为127,双精度为1023.从而所有浮点数的阶码值都可以变成非负整数,点数的比较和排序.便于浮IEEE754尾数形式为1.,其中F部分保存的的有效数字位,进一步提.这样可以保留是高数据表示的精确度.Floating PoDigital System IIslide 252
32、5S11位偏指数E52位有效尾数FS23位有效尾数F8位偏指数E与上述IEEE754格式相对应的32位浮点数的真值可表示为:N = (-1)S 2 1.FE-127随E和F取值不同,浮点数据表示具有不同的意义E=0, F =0:表示机器零;E=0, F 0:则N = (-1)S 20.F,非规格化浮点数;1.F,规格化浮点数;-1261 E 254:N = (-1)S 2E-127E=255, F =0E=255, F 0:无穷大,对应于x/0 (其中 x 0) ;:N= NaN,表示一个非数值,对应于0/0。Floating PoDigital System IIslide 26261.7C语言数据类型的含义典型的数据类型对应32位机的数据位宽Floating PoDigital System IIslide 27数据类型字节数char12short4long4char *4float(单精度浮点数)4double(双精度浮点数)81.7C语言数据类型的含义(续)例1. 6某大字节序的计算机系统内存中存放有如表1- 6所示数据,试地址 0 x1234 5678表示的,float,do
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年二手房买卖合同范本:含房屋交易纠纷处理规定
- 2025车库租赁合同范本:含停车管理服务条款
- 2025版危险品运输车辆驾驶员劳动合同履行与职业技能提升合同
- 2025海南省商业学校招聘事业编制人员(第二批)7人(第1号)考试参考试题及答案解析
- 2025海宁丁桥镇村级一类文化专职管理员招聘3人备考练习试题及答案解析
- 考点解析-贵州省凯里市7年级上册期末测试卷专题测试试卷(详解版)
- 考点解析沪科版9年级下册期末试卷含答案详解(模拟题)
- 安全教育演讲
- 基础强化北师大版8年级数学上册期中试题附完整答案详解(有一套)
- 铸造碳化钨制管工岗位操作技能考核试卷及答案
- 2025-2026年秋季第一学期学校“蒲公英”广播稿(22周):第1周 从烽火岁月里“穿越”来的青春答案
- 2025下半年系统集成项目管理师考试真题及答案
- 人教版七年级上册数学教学计划
- 2025云南昆明巫家坝建设发展有限责任公司招聘23人笔试备考试题及答案解析
- 2025年6月22日四川省市直事业单位遴选笔试真题及答案解析
- 2025年徐州市专业技术人员公需课程 - 心理调适
- 消防工程清包合同范本
- AQ 1083-2011 煤矿建设安全规范 (正式版)
- 创新创业基础-理论、案例与训练(大学生创新创业教育课程)全套教学课件
- 中海油一级供应商
- 病例报告表(CRF)模板
评论
0/150
提交评论