floa ng point numbers
play

Floa=ng-Point Numbers 2 Schedule Today Finish up - PowerPoint PPT Presentation

Computer Systems and Networks ECPE 170 Jeff Shafer University of the Pacific Floa=ng-Point Numbers 2 Schedule Today Finish up


  1. ì ¡ Computer ¡Systems ¡and ¡Networks ¡ ECPE ¡170 ¡– ¡Jeff ¡Shafer ¡– ¡University ¡of ¡the ¡Pacific ¡ Floa=ng-­‑Point ¡Numbers ¡

  2. 2 ¡ Schedule ¡ ì Today ¡ Finish ¡up ¡Floa=ng-­‑Point ¡Numbers ¡ ì Homework ¡#3 ¡assigned ¡ ì ì Monday ¡ Character ¡representa=on ¡ ì Homework ¡#2 ¡due ¡ ì Quiz ¡#1 ¡ ì ì Wednesday ¡ Boolean ¡Algebra ¡/ ¡Logic ¡ ì Homework ¡#3 ¡due ¡ ì Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  3. 3 ¡ Quiz ¡#1 ¡ ì Topics ¡from ¡Homework ¡1 ¡and ¡2 ¡ ì Conversion ¡between ¡decimal ¡and ¡binary ¡ ì Whole ¡numbers ¡and ¡frac=onal ¡numbers ¡ ì Signed ¡numbers ¡ ì Sign-­‑magnitude ¡ ì 1’s ¡complement ¡ ì 2’s ¡complement ¡ ì Conversion ¡between ¡hexadecimal ¡and ¡binary ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  4. 4 ¡ Quiz ¡#1 ¡ ì Topics ¡from ¡introductory ¡ ì Basic ¡computer ¡opera=on ¡ lectures ¡ Von ¡Neumann ¡model ¡ ì Basic ¡instruc=on ¡cycle ¡ ì ì History ¡of ¡computers ¡ ì Fetch ¡(from ¡where?) ¡ Vacuum ¡tubes ¡versus ¡ ì ì Decode ¡(what?) ¡ transistors? ¡ ì Execute ¡ Transistors ¡versus ¡ ì Key ¡components ¡ ì integrated ¡circuits? ¡ ì What ¡is ¡stored ¡in ¡ ì Moore’s ¡Law ¡ memory? ¡ ì What ¡does ¡the ¡ALU ¡do? ¡ What ¡does ¡it ¡mean? ¡ ì How ¡far ¡will ¡it ¡go? ¡ ì Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  5. 5 ¡ Recap ¡– ¡Floating-­‑Point ¡Representation ¡ ì “Simple ¡Model” ¡ ì 14 ¡bit ¡long ¡floa=ng-­‑point ¡number: ¡ ì The ¡sign ¡field ¡is ¡1 ¡bit ¡ ì The ¡exponent ¡field ¡is ¡5 ¡bits ¡ ì The ¡significand ¡field ¡is ¡8 ¡bits ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  6. 6 ¡ Recap ¡– ¡Floating-­‑Point ¡Representation ¡ ì Example: ¡Express ¡ -­‑26.625 10 ¡ in ¡the ¡revised ¡14-­‑bit ¡floa=ng-­‑ point ¡model ¡ ì 26.625 10 ¡= ¡11010.101 2 ¡x ¡2 0 ¡ Normalize ¡= ¡0.11010101 ¡x ¡2 5 . ¡ ì Use ¡excess ¡16 ¡biased ¡exponent: ¡ 16 ¡+ ¡5 ¡= ¡21 10 ¡(=10101 2 ) ¡ ì ì Also ¡need ¡a ¡1 ¡in ¡the ¡sign ¡bit ¡(nega=ve ¡number) ¡ ì Final ¡value ¡saved ¡to ¡memory: ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  7. 7 ¡ Biased ¡Exponent ¡– ¡Why? ¡ ì Why ¡does ¡the ¡simplified ¡model ¡(and ¡the ¡real ¡standard, ¡ described ¡next) ¡ use ¡a ¡biased ¡exponent ¡ to ¡store ¡posi=ve/ nega=ve ¡numbers, ¡instead ¡of ¡two’s ¡complement ¡ numbers? ¡ ì Only ¡answer ¡I ¡could ¡find: ¡ It ¡makes ¡comparing ¡two ¡floa=ng-­‑point ¡numbers ¡faster, ¡ ì even ¡on ¡integer ¡hardware ¡that ¡doesn’t ¡understand ¡ floa=ng-­‑point ¡fields ¡ Most ¡significant ¡bit ¡– ¡sign ¡bit ¡ ì Next ¡most ¡significant ¡group ¡– ¡Exponents, ¡which ¡are ¡ ì perfectly ¡arranged ¡in ¡ascending ¡order, ¡even ¡for ¡ “nega=ve” ¡exponents ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  8. 8 ¡ Floating-­‑Point ¡Representation ¡ ì Floa=ng-­‑point ¡addi=on ¡and ¡subtrac=on ¡are ¡done ¡ using ¡methods ¡analogous ¡to ¡how ¡we ¡perform ¡ calcula=ons ¡using ¡pencil ¡and ¡paper ¡ ì The ¡first ¡thing ¡that ¡we ¡do ¡is ¡express ¡both ¡operands ¡ in ¡the ¡same ¡exponen=al ¡power, ¡then ¡add ¡the ¡ numbers, ¡preserving ¡the ¡exponent ¡in ¡the ¡sum ¡ ì If ¡the ¡exponent ¡requires ¡adjustment, ¡we ¡do ¡so ¡at ¡ the ¡end ¡of ¡the ¡calcula=on ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  9. 9 ¡ Floating-­‑Point ¡Representation ¡ ì Example: ¡Find ¡12 10 ¡+ ¡ ¡1.25 10 ¡using ¡the ¡14-­‑bit ¡simple ¡ floa=ng-­‑point ¡model ¡ ì 12 10 ¡= ¡0.1100 ¡x ¡2 4 ¡ 1.25 10 ¡= ¡0.101 ¡x ¡2 1 ¡= ¡0.000101 ¡x ¡2 4 ¡ • Thus, ¡the ¡sum ¡is ¡ 0.110101 ¡x ¡2 4 ¡ ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  10. 10 ¡ Floating-­‑Point ¡Representation ¡ ì Floa=ng-­‑point ¡mul=plica=on ¡is ¡also ¡carried ¡out ¡in ¡a ¡ manner ¡akin ¡to ¡how ¡we ¡perform ¡mul=plica=on ¡ using ¡pencil ¡and ¡paper. ¡ ì Mul=ply ¡the ¡two ¡significands ¡ ì Add ¡their ¡exponents ¡ ì If ¡the ¡exponent ¡requires ¡adjustment, ¡do ¡so ¡at ¡the ¡ end ¡of ¡the ¡calcula=on ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  11. 11 ¡ ì ¡ The ¡ Real ¡Floating-­‑Point ¡Model ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  12. 12 ¡ IEEE ¡Floating-­‑Point ¡Representation ¡ ì The ¡IEEE ¡has ¡established ¡standards ¡for ¡floa=ng-­‑point ¡ numbers ¡ ì IEEE-­‑754 ¡single ¡precision ¡ standard ¡( 32 ¡bits ¡ long) ¡ 8 -­‑bit ¡exponent ¡(with ¡a ¡ bias ¡of ¡127 ) ¡ ì 23 -­‑bit ¡significand ¡ ì A ¡“float” ¡in ¡C++ ¡ ì ì IEEE-­‑754 ¡double ¡precision ¡ standard ¡( 64 ¡bits ¡ long) ¡ 11 -­‑bit ¡exponent ¡(with ¡a ¡ bias ¡of ¡1023 ) ¡ ì 52 -­‑bit ¡significand ¡ ì A ¡“double” ¡in ¡C++ ¡ ì Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  13. 13 ¡ IEEE ¡Floating-­‑Point ¡Representation ¡ ì Watch ¡out! ¡Significand ¡is ¡normalized ¡differently ¡ ì Implied ¡1 ¡to ¡the ¡ leT ¡ of ¡the ¡radix ¡point, ¡i.e. ¡ formaked ¡as ¡1.xxxxxxx… ¡ ì For ¡example, ¡4.5 ¡= ¡.1001 ¡x ¡2 3 ¡ ¡ In ¡IEEE ¡format, ¡use ¡4.5 ¡= ¡1.001 ¡x ¡2 2 ¡ ¡ ¡ ì The ¡1 ¡is ¡ implied , ¡which ¡means ¡it ¡is ¡ not ¡saved ¡in ¡ computer ¡memory ¡ ì The ¡stored ¡significand ¡would ¡include ¡only ¡001 ¡ ì Op=miza=on ¡– ¡This ¡saves ¡one ¡en=re ¡bit! ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  14. 14 ¡ IEEE ¡Floating-­‑Point ¡Representation ¡ ì Example: ¡Express ¡ -­‑3.75 ¡ as ¡a ¡floa=ng ¡point ¡number ¡using ¡ IEEE ¡ single ¡precision. ¡ ì Normalize ¡according ¡to ¡IEEE ¡rules: ¡ -­‑3.75 ¡= ¡-­‑11.11 2 ¡= ¡-­‑1.111 ¡x ¡2 1 ¡ ì The ¡bias ¡for ¡ single ¡precision ¡is ¡127, ¡so ¡add ¡127 ¡+ ¡1 ¡= ¡128 ¡ ì ì This ¡is ¡the ¡exponent ¡saved ¡to ¡computer ¡memory ¡ The ¡first ¡1 ¡in ¡the ¡significand ¡is ¡implied, ¡so ¡we ¡have: ¡ ì To ¡decode ¡saved ¡number ¡with ¡the ¡implied ¡1 ¡in ¡the ¡ ì significand: ¡ (implied ¡1. ¡ not ¡saved) ¡ ì -­‑(1).111 2 ¡x ¡2 (128 ¡– ¡127) ¡= ¡-­‑1.111 2 ¡x ¡2 1 ¡= ¡-­‑11.11 2 ¡= ¡-­‑3.75. ¡ ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  15. 15 ¡ IEEE ¡Floating-­‑Point ¡Representation ¡ ì Using ¡the ¡IEEE-­‑754 ¡single ¡precision ¡floa=ng ¡point ¡ standard: ¡ ¡ ì An ¡exponent ¡of ¡255 ¡indicates ¡a ¡special ¡value. ¡ ì If ¡the ¡significand ¡is ¡zero, ¡the ¡value ¡is ¡ ¡ ± ¡infinity. ¡ ì If ¡the ¡significand ¡is ¡nonzero, ¡the ¡value ¡is ¡NaN, ¡“not ¡a ¡ number,” ¡ooen ¡used ¡to ¡flag ¡an ¡error ¡condi=on. ¡ ì Using ¡the ¡double ¡precision ¡standard: ¡ ì An ¡exponent ¡of ¡2047 ¡indicates ¡a ¡special ¡value ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend