资源描述:
《Floating-PointArithmetic》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Floating-PointArithmeticReading:StudyChapter3.6-3.7Skim3.8-3.10if((A+A)-A==A){SelfDestruct()}Whatistheproblem?ManynumericapplicationsrequirenumbersoveraVERYlargerange.(e.g.nanosecondstocenturies)Mostscientificapplicationsrequirerealnumbers(e.g.)Butsof
2、arweonlyhaveintegers.We*COULD*implementthefractionsexplicitly(e.g.½,1023/102934)We*COULD*usebiggerintegersFloatingpointisabetteranswerformostapplications.RecallScientificNotationLet’sstartourdiscussionoffloatingpointbyrecallingscientificnotationfromhig
3、hschoolNumbersrepresentedinparts:42=4.200x1011024=1.024x103-0.0625=-6.250x10-2Arithmeticisdoneinpieces10241.024x103-42-0.042x1039820.982x1039.820x102Beforeadding,wemustmatchtheexponents,effectively“denormalizing”thesmallermagnitudenumberWethen“normaliz
4、e”thefinalresultsothereisonedigittotheleftofthedecimalpointandadjusttheexponentaccordingly.SignificantDigitsExponentMultiplicationinScientificNotationIsstraightforward:MultiplytogetherthesignificantpartsAddtheexponentsNormalizeifrequiredExamples:10241.
5、024x103x0.06256.250x10-2646.400x101424.200x101x0.06256.250x10-22.62526.250x10-12.625x100(Normalized)Inmultiplication,howfaristhemostyouwillevernormalize?Inaddition?FP==“Binary”ScientificNotationIEEEsingleprecisionfloating-pointformat0x42280000inhexadec
6、imalExponent:Unsigned“Bias127”8-bitintegerE=Exponent+127Exponent=10000100(132)–127=5Significand:Unsignedfixedbinarypointwith“hidden-one”Significand=“1”+0.01010000000000000000000=1.3125PuttingitalltogetherN=-1S(1+F)x2E-127=-10(1.3125)x25=42100001000101
7、00000000000000000000“F”Significand(Mantissa)-1“E”Exponent+127“S”SignBitExampleNumbersOneSign=+,Exponent=0,Significand=1.0-10(1.0)x20=1S=0,E=0+127,F=1.0–‘1’001111111000000000000000000000000x3f800000One-halfSign=+,Exponent=-1,Significand=1.0-10(1.0)
8、x2-1=½S=0,E=-1+127,F=1.0–‘1’001111110000000000000000000000000x3f000000MinusTwoSign=-,Exponent=1,Significand=1.0110000000000000000000000000000000xc0000000ZerosHowdoyourepresent0?ZeroSign=?,Exponent=?,Significand=?Here’swherethehidde