÷ƒ’À;è TeX output 1998.01.17:2004‹ÿÿÿÿ y ý£ ? þ’Ãø×óDÓítG®G®cmr17¹The–7tó߆µTG® cmtt12ºcalc“¹pacŒqk‘ÿäageŽŸ’û¯In x–7tnotation“arithmetic“in“LŸüdú‘úKGóX«Q cmr12»AŽŽ‘¹”¹T‘ý[™Ÿ¸-EŽ‘;gXŸùº¯ó!",š cmsy10¿ŽŽŽŸ’˜ O»Kresten–ê¨Krab“ThorupŽŽŽŽ’+¬F‘ÿVrank‘ê¨JensenŽŽŽŽŽŸ37’æ 1997/11/11ŽŸ.’ï!Kót ‰: cmbx9ÇAbstractŽŸ¬Ñ‘xßüóo´‹Ç cmr9ÆThe–W÷óߤN cmtt9Ècalc“Æpacš¾9k‘ÿ|rage“reimplemen˜ts“the“LŸýó5‘ü«‡ó¹Aa¨cmr6ÁAŽŽ‘© ÆT‘þuAŸïÿEŽ‘˜ŸX“commands“È\setcounterÆ,ޤ ‘kÈ\addtocounterÆ,–$ØÈ\setlengthÆ,“and–!½È\addtolengthÆ.‘A¬Instead“of“a“simple“v‘ÿ|ralue,Ž¡‘kthese–Tcommands“no¾9w“accept“an“in x“notation“expression.Ž©!Ä‘Ró!ÂÖN ff cmbx12Ì1Ž‘jLËInŒÌtros3ductionŽŸç‘RóKñ`y cmr10²Arithmetic–’in“T‘þU>Ÿ'EŽ‘ãxX“is“done“using“lo•¸ãw-lev“el–’opGerations“suc¸ãh“as“ó"ßêŸ'EŽ‘ãxX.Ž¡‘aThe–­Ÿin x“expressions“can“bGe“used“in“argumenš¸ãts“to“macros“(the“Ícalc“²pac˜k‘ÿqÇageŽ¡‘RdošGesn't–UUemplo¸ãy“category“co˜de“cš¸ãhanges“to“ac˜hiev˜e“its“goals).ަ‘RÌ2Ž‘jLËInformal‘ffdescriptionŽŸç‘R²Standard–õdLŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ‘ãxX“proš¸ãvides“the“follo˜wing“set“of“commands“to“manipulate“coun˜tersŽ¡‘Rand–UUlengths“[2Ž‘,“pages“194“and“216].Ž©‘RÍ\setcounter{ó#ý': cmti10Îctr‘Í}{Înum‘ÄcÍ}–'¦²sets“the“v›ÿqÇalue“of“the“coun¸ãter“Îctr‘;3²equal“to“(the“v˜alue“of‘Ç)Ž¡‘kÎnum².‘qÇ(F‘ÿ*ªragile)ަ‘RÍ\addtocounter{Îctr‘Í}{Înum‘ÄcÍ}–²incremenš¸ãts“the“v‘ÿqÇalue“of“the“coun˜ter“Îctr‘$޲b˜y“(the“v‘ÿqÇalueŽ¡‘kof‘Ç)‘UUÎnum².‘qÇ(F‘ÿ*ªragile)Ž‘RŸæf‰ffÿrŸ @‘ ÷ˆŸý-:óq¡% cmsy6ÅŽŽ‘LÜó|{Ycmr8ÀW›ÿJªe–ßthank“F˜rank“MittelbacšÃŽh“for“his“v‡aluable“commen˜ts“and“suggestions“whic˜h“ha˜v˜e“greatlyŽŸ €impro•ÃŽv“ed–ÕXthis“pacÃŽk‡age.ŽŽŸ’²1ŽŽŒ‹* y ý£ ? ýä‘RÍ\setlength{Îcmd‘‰Í}{Îlen‘ÄcÍ}–NÞ²sets“the“v‘ÿqÇalue“of“the“length“command“Îcmd‘Wg²equal“to“(theޤ ‘kv‘ÿqÇalue–UUof‘Ç)“Îlen².‘qÇ(Robust)ŽŸªª‘RÍ\addtolength{Îcmd‘‰Í}{Îlen‘ÄcÍ}–L²sets“the“v‘ÿqÇalue“of“the“length“command“Îcmd‘ Õ²equal“to“itsŽ¡‘kcurren¸ãt–UUv›ÿqÇalue“plus“(the“v˜alue“of‘Ç)“Îlen².‘qÇ(Robust)Ž©UU‘R(The–ÅÍ\setcounter“²and“Í\addtocounter“²commands“ha•¸ãv“e–Åglobal“e ect,‘Q!while“theŽ¡‘RÍ\setlength–t`²and“Í\addtolength“²commands“obGey“the“normal“scoping“rules.)‘ÎéInŽ¡‘Rstandard–ë§LŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ‘ãxX,‘;the“argumenš¸ãts“to“these“commands“m˜ust“bGe“simple“v‘ÿqÇalues.‘4¼TheŽ¡‘RÍcalc–E²pac¸ãk‘ÿqÇage“extends“these“commands“to“accept“in x“notation“expressions,‘Ide-Ž¡‘Rnoting–¶Ôv‘ÿqÇalues“of“appropriate“tš¸ãypGes.‘–DUsing“the“Ícalc“²pac˜k‘ÿqÇage,‘Ï4Înum‘{7²is“replaced“b˜yŽ¡‘Ró !",š cmsy10¸h²inš¸ãteger–xjexpression¸i²,‘/and“Îlen‘<Ͳis“replaced“b˜y“¸h²glue“expression¸i².‘ÛThe“formal“syn˜taxŽ¡‘Rof–UU¸h²inš¸ãteger“expression¸i“²and“¸h²glue“expression¸i“²is“giv˜en“bGelo˜w.Ž¡‘aIn–1ùaddition“to“these“commands“to“explicitly“set“a“length,‘i"man¸ãy“LŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ‘ãxX“com-Ž¡‘Rmands–ñtakš¸ãe“a“length“argumen˜t.‘¹šAfter“loading“this“pac˜k‘ÿqÇage,‘H—most“of“these“com-Ž¡‘Rmands–>will“accept“a“¸h²glue“expression¸i².‘XThis“includes“the“optional“width“argumen¸ãtŽ¡‘Rof–Í\makebox²,›¶¹the“width“argumen¸ãt“of“Í\parbox²,˜Íminipage²,˜and“a“Ítabluar“p²-column,Ž¡‘Rand–œ8manš¸ãy“similar“constructions.‘4(This“pac˜k‘ÿqÇage“doGes“not“rede ne“an˜y“of“these“com-Ž¡‘Rmands,‘³but–ó:they“are“de ned“bš¸ãy“default“to“read“their“argumen˜ts“b˜y“Í\setlengthŽ¡‘R²and–°ûso“automatically“bGene t“from“the“enhanced“Í\setlength“²command“pro¸ãvidedŽ¡‘Rbš¸ãy–UUthis“pac˜k‘ÿqÇage.)Ž¡‘aIn–e•the“follo•¸ãwing,‘i¥w“e–e•shall“use“standard“T‘þU>Ÿ'EŽ‘ãxX“terminology‘ÿ*ª.‘¢‡The“correspGondenceŽ¡‘RbGet•¸ãw“een–·»T‘þU>Ÿ'EŽ›ãxX“and“LŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ˜X“terminology“is“as“follo¸ãws:‘6“LŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ˜X“coun¸ãters“correspGondŽ¡‘Rto–tvT‘þU>Ÿ'EŽ‘ãxX's“counš¸ãt“registers;‘they“hold“quan˜tities“of“t˜ypGe“¸h²n˜um˜bGer¸i².‘Ï+LŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ‘ãxX“lengthŽ¡‘Rcommands–šcorrespšGond“to“T‘þU>Ÿ'EŽ‘ãxX's“dimen“(for“rigid“lengths)“and“skip“(for“rubb˜erŽ¡‘Rlengths)–UUregisters;“they“hold“quanš¸ãtities“of“t˜ypšGes“¸h²dimen¸i“²and“¸h²glue¸i²,“resp˜ectiv¸ãely‘ÿ*ª.Ž¡‘aT‘þU>Ÿ'EŽ‘ãxX–¬™givš¸ães“us“primitiv˜e“opšGerations“to“p˜erform“arithmetic“on“registers“as“follo¸ãws:ަ‘a¸ŽŽŽ‘k²addition–UUand“subtraction“on“all“tš¸ãypGes“of“quan˜tities“without“restrictions;Ž©ªª‘a¸ŽŽŽ‘k²mš¸ãultiplication–1and“division“b˜y“an“Îinte‘ÿ}'ger‘’¾²can“bšGe“p˜erformed“on“a“register“ofŽ¡‘kan•¸ãy‘UUt“ypGe;ަ‘a¸ŽŽŽ‘k²m•¸ãultiplication›ˆýb“y˜a˜Îr–ÿ}'e“al‘‘†²n•¸ãum“bGer˜(i.e.,‘±Üa˜n“um“b•Ger˜with˜a˜fractional˜part)˜can˜b“eŽ¡‘kpGerformed–4Çon“a“register“of“anš¸ãy“t˜ypGe,‘;Jbut“the“stretc˜h“and“shrink“compGonen˜tsŽ¡‘kof–UUa“glue“quan•¸ãtit“y–UUare“discarded.ŽŸUU‘RThe–béÍcalc“²pacš¸ãk‘ÿqÇage“uses“these“T‘þU>Ÿ'EŽ‘ãxX“primitiv˜es“but“pro˜vides“a“more“user-friendlyŽ¡‘Rnotation–UUfor“expressing“the“arithmetic.Ž¡‘aAn–m=expression“is“formed“of“nš¸ãumerical“quan˜titites“(suc˜h“as“explicit“constan˜ts“andŽ¡‘RLŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ‘ãxX–Ä£counš¸ãters“and“length“commands)“and“binary“opGerators“(the“tok˜ens“`Í+²',‘àw`Í-²',Ž¡‘R`Í*²',‘Àûand–›ä`Í/²'“with“their“usual“meaning)“using“the“familiar“in x“notation;‘Ùµparen¸ãthesesŽ¡‘Rmaš¸ãy–bÔbGe“used“to“o˜v˜erride“the“usual“precedences“(that“m˜ultiplication/division“ha˜v˜eŽ¡‘Rhigher–UUprecedence“than“addition/subtraction).Ž¡‘aExpressions–žÄm¸ãust“bšGe“prop˜erly“t¸ãyp˜ed.‘4ìThis“means,–ÃHe.g.,“that–žÄa“dimen“expressionŽ¡‘Rmš¸ãust–Þ{bGe“a“sum“of“dimen“terms:‘6Zi.e.,‘öAy˜ou“cannot“sa˜y“`Í2cm+4²'“but“`Í2cm+4pt²'“is“v‘ÿqÇalid.Ž¡‘aIn–f®a“dimen“term,‘kthe“dimension“part“m¸ãust“come“ rst;‘oZthe“same“holds“for“glueŽ¡‘Rterms.‘5 Also,‘Ñmš¸ãultiplication–Ÿ and“division“b˜y“non-in˜teger“quan˜tities“require“a“spGecialŽ¡‘Rsynš¸ãtax;–UUsee“bGelo˜w.ŽŽŸ’2ŽŽŒ‹ G y ý£ ? ýä‘a²Ev‘ÿqÇaluation–¬—of“subšGexpressions“at“the“same“lev¸ãel“of“precedence“pro˜ceeds“from“leftޤ ‘Rto–' righš¸ãt.‘b`Consider“a“dimen“term“suc˜h“as“\Í4cm*3*4²".‘b`First,‘0^the“v‘ÿqÇalue“of“the“factorŽ¡‘RÍ4cm–<`²is“assigned“to“a“dimen“register,‘v"then“this“register“is“mš¸ãultiplied“b˜y“3“(usingŽ¡‘RÍ\multiply²),–UWand,“ nally‘ÿ*ª,“the“register“is“mš¸ãultiplied“b˜y“4“(again“using“Í\multiply²).Ž¡‘RThis–Œ5also“explains“wh¸ãy“the“dimension“part“(i.e.,‘´othe“part“with“the“unit“designation)Ž¡‘Rmš¸ãust–f¶come“ rst;‘ofT‘þU>Ÿ'EŽ‘ãxX“simply“doGesn't“allo˜w“un˜t˜ypGed“constan˜ts“to“bGe“assigned“to“aŽ¡‘Rdimen‘UUregister.Ž¡‘aThe–ÂÕÍcalc“²pacš¸ãk‘ÿqÇage“also“allo˜ws“m˜ultiplication“and“division“b˜y“real“n˜um˜bGers.Ž¡‘RHo•¸ãw“ev“er,‘”îa–ˆ6spGecial“synš¸ãtax“is“required:‘׉y˜ou“m˜ust“use“Í\real{¸h²decimal“constan˜t¸iÍ}Ÿü^ÿ±1ŽŽŽ¡‘R²or–pZÍ\ratio{¸h²dimen“expression¸iÍ}{¸h²dimen“expression¸iÍ}“²to“denote“a“real“v‘ÿqÇalue“to“bGeŽ¡‘Rused–’Úfor“mš¸ãultiplication/division.‘*UThe“ rst“form“has“the“ob˜vious“meaning,‘â:andŽ¡‘Rthe–Ùsecond“form“denotes“the“n•¸ãum“bGer–Ùobtained“b¸ãy“dividing“the“v‘ÿqÇalue“of“the“ rstŽ¡‘Rexpression–UUb¸ãy“the“v‘ÿqÇalue“of“the“second“expression.Ž¡‘aT‘þU>Ÿ'EŽ‘ãxX–ˆâdiscards“the“stretcš¸ãh“and“shrink“compGonen˜ts“of“glue“when“glue“is“m˜ultipliedŽ¡‘Rbš¸ãy–UUa“real“n˜um˜bGer.‘qÇSo,“for“example,Ž©‘dæXÈ\setlength{\parskip}{3pt–¹–plus“3pt“*“\real{1.5}}ŽŸ‘R²will–ô±set“the“paragraph“separation“to“4.5pt“with“no“stretcš¸ãh“or“shrink.‘Q(Inciden˜tally‘ÿ*ª,Ž¡‘Rnote–UUhoš¸ãw“spaces“can“bGe“used“to“enhance“readabilit˜y‘ÿ*ª.)Ž¡‘aWhen–‘`T‘þU>Ÿ'EŽ‘ãxX“pGerforms“arithmetic“on“in•¸ãtegers,‘ can“y–‘`fractional“part“of“the“resultsŽ¡‘Rare–UUdiscarded.‘qÇF‘ÿ*ªor“example,ަ‘dæXÈ\setcounter{x}{7/2}ޤ ‘dæX\setcounter{y}{3*\real{1.6}}Ž¡‘dæX\setcounter{z}{3*\real{1.7}}ŽŸ‘R²will–ø³assign“the“v›ÿqÇalue“3“to“the“coun¸ãter“Íx²,‘!‹the“v˜alue“4“to“Íy²,‘!‹and“the“v˜alue“5“to“Íz².ޤ ‘RThis–Îtruncation“also“applies“to“Îinterme‘ÿ}'diate‘Ã)²results“in“the“sequen¸ãtial“computationŽ¡‘Rof–UUa“compGosite“expression;“thš¸ãus,“the“follo˜wing“commandަ‘dæXÈ\setcounter{x}{3–¹–*“\real{1.6}“*“\real{1.7}}ŽŸ‘R²will–UUassign“6“to“Íx².Ž¡‘aAs–±¦an“example“of“the“use“of“Í\ratio²,‘Ⱥconsider“the“problem“of“scaling“a“ gureŽ¡‘Rto–ɼošGccup¸ãy“the“full“width“(i.e.,‘æÕÍ\textwidth²)“of“the“b˜o˜dy“of“a“page.‘ÎûAssume“thatŽ¡‘Rthe–Ÿ'EŽ‘ãxXb•Go“ok–‘à[1Ž‘].‘'gW‘ÿ*ªe“use“Îtyp‘ÿ}'e‘R;²as“a“meta-v¸ãeriable,‘¡standing“forޤ ‘R`in¸ãteger',–UU`dimen',“and“`glue'.Ÿü^ÿ±2ŽŽŽ©›‘a¸hÎtyp‘ÿ}'e‘°²expression¸iŽ’±Ä›ŽŽŽ’·á!‘UUhÎtyp‘ÿ}'e‘°²term¸iŽŽ¡‘j‘UUhÎtyp‘ÿ}'e‘°²expression¸iŽ‘MoFh²plus–UUor“min¸ãus¸iŽ’„¤hÎtyp‘ÿ}'e‘°²term¸iŽŽ¦‘ahÎtyp‘ÿ}'e‘°²term¸iŽ’™}|ŽŽŽ’Ÿ™ò!‘UUhÎtyp‘ÿ}'e‘°²factor¸iŽŽ¡‘j‘UUhÎtyp‘ÿ}'e‘°²term¸iŽ‘5('h²m¸ãultiply–UUor“divide¸iŽ’‹’àh²in¸ãteger‘UUfactor¸iŽŽ¡‘j‘UUhÎtyp‘ÿ}'e‘°²term¸iŽ‘5('h²m¸ãultiply–UUor“divide¸iŽ’‹’àh²real‘UUn•¸ãum“bGer¸iŽŽ¦‘ahÎtyp‘ÿ}'e‘°²factor¸iŽ’ž6aŽŽŽ’¤R×!‘UUhÎtyp‘ÿ}'e‘À[¸iŽ‘#è$j‘UUÍ(Ÿÿ±12Ž‘xæ¸hÎtyp‘ÿ}'e‘°²expression¸iŽ‘R’×Í)Ÿÿ±12ŽŽ¦‘a¸h²in¸ãteger¸iŽ’‰ÜvŽŽŽ’øì!‘UUh²n•¸ãum“bGer¸iŽŽ¦‘ah²m¸ãultiply–UUor“divide¸iŽ’¾cŽŽŽ’Ä1Ù!–UUÍ*Ÿÿ±12Ž‘#¸j“Í/Ÿÿ±12ŽŽ¦‘a¸h²real‘UUn•¸ãum“bGer¸iŽ’¤ŽŽŽ’ª}!–UUÍ\ratio{¸h²dimen“expression¸iŽ›R£™Í}{¸h²dimen“expression¸iŽ˜Í}Ž¡‘¸j–UUÍ\real{¸h²decimal“constan¸ãt¸iŽ‘QqÒÍ}ŽŸ çg‘RÌ4Ž‘jLËThe–ffev‘ÿ™aluation“scŒÌhemeŽŸç‘R²In–x·this“section,‘Áwš¸ãe“shall“for“simplicit˜y“consider“only“expressions“con˜taining“`+'Ž¡‘R(addition)–‘}and“`¸²'“(m¸ãultiplication)“opGerators.‘&>It“is“trivial“to“add“subtraction“andŽ¡‘Rdivision.Ž¡‘aAn–‚vexpression“ó  b> cmmi10µE‘²is“a“sum“of“terms:‘̵TŸÿ±1Ž‘~²+‘Ÿ¸–ª¨“Ž‘­å²+‘ŸµTŸÿó 0e—rcmmi7´nŽ‘q~²;‘a“term“is“a“proGduct“ofŽ¡‘Rfactors:‘9cµFŸÿ±1ޑӯ¸‘WS–ª¨“Ž‘YM‘WSµFŸÿ´mŽ‘˜›²;‘ %a–äfactor“is“either“a“simple“nš¸ãumeric“quan˜tit˜y“µf‘ø²(lik˜e“¸h²n˜um˜bGer¸iŽ¡‘R²as–UUdescribšGed“in“the“T‘þU>Ÿ'EŽ‘ãxXb˜o˜ok),“or“a“paren¸ãthesized“expression“(µE‘“Ÿü^ÿó O!â…cmsy7·0Ž‘aƲ).Ž¡‘aSince–[Ëthe“T‘þU>Ÿ'EŽ‘ãxX“engine“can“only“execute“arithmetic“opGerations“in“a“mac¸ãhine-Ž¡‘RcoGde–¹likš¸ãe“manner,‘Òw˜e“ha˜v˜e“to“ nd“a“w˜a˜y“to“translate“the“in x“notation“in˜to“thisŽ¡‘R`instruction‘UUset'.Ž¡‘aOur–ë‹goal“is“to“design“a“translation“sc¸ãheme“that“translates“µX‘´m²(an“expression,Ž¡‘Ra–ïterm,‘sor“a“factor)“inš¸ãto“a“sequence“of“T‘þU>Ÿ'EŽ‘ãxX“instructions“that“doGes“the“follo˜wingŽ¡‘R[In•¸ãv‘ÿqÇariance›PropGert“y]:‘éWcorrectly˜ev‘ÿqÇaluates˜µX‘Èâ²,‘@lea“v“es˜the˜result˜in˜a˜global˜regis-Ž¡‘Rter–ÜõA“²(using“a“global“assignmen¸ãt),‘ôáand“došGes“not“p˜erform“global“assignmen¸ãts“to“theŽ¡‘Rscratcš¸ãh–register“µB‘€q²;‘-,moreo˜v˜er,‘%#the“coGde“sequence“m˜ust“bšGe“balanced“with“resp˜ect“toŽ¡‘RT‘þU>Ÿ'EŽ‘ãxX–UUgroups.‘qÇW‘ÿ*ªe“shall“denote“the“cošGde“sequence“corresp˜onding“to“µX‘7²b¸ãy“[–þUX[µX‘Èâ²]“].Ž¡‘aIn–UUthe“replacemen¸ãt“cošGde“sp˜eci ed“b˜eloš¸ãw,“w˜e“use“the“follo˜wing“con˜v˜en˜tions:ŽŸ;5‘a¸ŽŽŽ‘kµA–Ýc²and“µB‘]Ô²denote“registers;‘_all“assignmen¸ãts“to“µA“²will“bGe“global,‘õ`and“all“assign-Ž¡‘kmen¸ãts–UUto“µB‘ÕÆ²will“bšGe“lo˜cal.ޤš‘a¸ŽŽŽ‘k²\¸(²"–UUmeans“global“assignmen¸ãt“to“the“register“on“the“lhs.Ž¡‘a¸ŽŽŽ‘k²\¸ ²"–UUmeans“loGcal“assignmen¸ãt“to“the“register“on“the“lhs.Ž¡‘a¸ŽŽŽ‘k²\ŸÎ:´,‘þ¢_·!±[´C}‚±]ŽŽ‘<<²"–ªïmeans“\sa•¸ãv“e–ªïthe“coGde“µC‘b ²unš¸ãtil“the“curren˜t“group“(scopGe)“ends,‘ÀUthenŽŸ ‘kexecute–UUit."‘qÇThis“correspGonds“to“the“T‘þU>Ÿ'EŽ‘ãxX-primitiv¸ãe“Í\aftergroup².Ž¡‘a¸ŽŽŽ‘k²\¸f²"–UUdenotes“the“start“of“a“new“group,“and“\¸g²"“denotes“the“end“of“a“group.Ž‘RŸ„‰ffÿrŸ J=‘ "5Ÿý-:Á2ŽŽŽ‘LÜÀThis–ÕXvšÃŽersion“of“the“ó$ßCÊscmtt8Ïcalc“Àpac˜k‡age“došŸ'EŽ‘ãxX“parse“it.ŽŽŸ’5ŽŽŒ‹7Ÿ y ý£ ? ýä‘RÌ5Ž‘jLËImplemenŒÌtationŽŸç‘R²F‘ÿ*ªor–UUbrevit¸ãy“de neޤ‘a¸h²n¸ãumeric¸iŽ’ŽÜwŽŽŽ’”øí!‘UUh²n•¸ãum“bGer¸iŽ‘/‡"j‘UUh²dimen¸iŽ‘)wj‘UUh²glue¸iŽ‘ 8çj‘UUh²m¸ãuglue¸iŽŽ¡‘a²So–Àfar“wš¸ãe“ha˜v˜e“ignored“the“question“of“ho˜w“to“determine“the“t˜ypGe“of“registerޤ ‘Rto–USbšGe“used“in“the“co˜de.‘qÂHo•¸ãw“ev“er,‘•Sit–USis“easy“to“see“that“(1)“`¸²'“alw•¸ãa“ys‘USinitiatesŽ¡‘Ran–^þ¸h²inš¸ãteger“factor¸i²,‘¡h(2)“all“¸h²n˜umeric¸i²s“in“an“expression,‘¡hexcept“those“whic˜h“areŽ¡‘Rpart–˜Ãof“an“¸h²inš¸ãteger“factor¸i²,‘©Ÿare“of“the“same“t˜ypGe“as“the“whole“expression,‘©Ÿand“allŽ¡‘R¸h²nš¸ãumeric¸i²s–UUin“an“¸h²in˜teger“factor¸i“²are“¸h²n˜um˜bGer¸i²s.Ž¡‘aW‘ÿ*ªe›¥ha•¸ãv“e˜to˜ensure˜that˜µA˜²and˜µB‘%r²alw“a“ys˜ha“v“e˜an˜appropriate˜t“ypGe˜for˜theŽ¡‘R¸h²nš¸ãumeric¸i²s–°>they“manipulate.‘‚‚W‘ÿ*ªe“can“ac˜hiev˜e“this“b˜y“ha˜ving“an“instance“of“µAŽ¡‘R²and–ÊϵB‘K@²for“eacš¸ãh“t˜ypšGe.‘C›Initially‘ÿ*ª,‘愵A“²and“µB‘K@²refer“to“registers“of“the“prop˜er“t¸ãyp˜e“for“theŽ¡‘Rwhole– ¿expression.‘YêWhen“an“¸h²inš¸ãteger“factor¸i“²is“expGected,‘w˜e“m˜ust“c˜hange“µA“²and“µBŽ¡‘R²to–ÆBrefer“to“inš¸ãteger“t˜ypGe“registers.‘BW‘ÿ*ªe“can“accomplish“this“b˜y“including“instructionsŽ¡‘Rto–acš¸ãhange“the“t˜ypGe“of“µA“²and“µB‘„Ò²to“in˜teger“t˜ypGe“as“part“of“the“replacemen˜t“coGdeŽ¡‘Rfor–ë`¸²;‘m5if“wš¸ãe“appGend“suc˜h“instructions“to“the“replacemen˜t“cošGde“describ˜ed“ab˜o•¸ãv“e,Ž¡‘Rwš¸ãe–Çalso“ensure“that“the“t˜ypGe-c˜hange“is“loGcal“(pro˜vided“that“the“t˜ypGe-c˜hangingŽ¡‘Rinstructions–4¾only“ha•¸ãv“e–4¾loGcal“e ect).‘fêHo•¸ãw“ev“er,‘;Cnote–4¾that“the“instance“of“µA“²referredŽ¡‘Rto–UUin“ŸÎ:´,‘þ¢_·!±[´B•W=· ´B“·´A±]ŽŽ‘3†}²is“the“in¸ãteger“instance“of“µA².Ž¡‘aW‘ÿ*ªe–shall“use“Í\begingroup“²and“Í\endgroup“²for“the“opGen-group“and“close-groupŽ¡‘Rc•¸ãharacters.‘’uThis›µa“v“oids˜problems˜with˜spacing˜in˜math˜(as˜pGoin“ted˜out˜to˜us˜b“yŽ¡‘RF‘ÿ*ªrank‘UUMittelbac¸ãh).Ž©þ6‘Ró%ÂÖN  cmbx12Ð5.1Ž‘pÀGetting‘€startedŽŸuT‘R²No•¸ãw›Å>w“e˜ha“v“e˜enough˜insigh“t˜to˜do˜the˜actual˜implemen“tation˜in˜T‘þU>Ÿ'EŽ‘ãxX.‘ÁFirst,‘á8w“eŽ¡‘Rannounce–UUthe“macro“pac¸ãk‘ÿqÇageŸü^ÿ±3ŽŽ‘|s².ŽŸ‘Uüs±1Ž‘\ª®ó©±Ê cmsy9Êhó&ÒoÇw cmss9Ñpack¾9ageŽ‘#g Êiޤ ‘Uüs±2Ž‘\ª®È%\NeedsTeXFormat{LaTeX2e}Ž¡‘Uüs±3Ž‘\ª®È%\ProvidesPackage{calc}[\filedate\space\fileversion]ަ‘RÐ5.2Ž‘pÀAssignmen t‘€macrosŽŸuT‘鯲È\calc@assign@genericŽŽŽ‘R²The–KÍ\calc@assign@generic“²macro“takš¸ães“four“argumen˜ts:‘lë(1“and“2)“the“registersޤ ‘Rto–$=bšGe“used“for“global“and“lo˜cal“manipulations,‘Wöresp˜ectiv¸ãely;‘‹±(3)“the“lv‘ÿqÇalue“part;Ž¡‘R(4)–UUthe“expression“to“bGe“ev‘ÿqÇaluated.Ž¡‘aThe–”Ðthird“argumen¸ãt“(the“lv‘ÿqÇalue)“will“bGe“used“as“a“pre x“to“a“register“thatŽ¡‘Rconš¸ãtains–UUthe“v‘ÿqÇalue“of“the“spGeci ed“expression“(the“fourth“argumen˜t).Ž¡‘aIn–<=general,‘tuan“lv‘ÿqÇalue“is“anš¸ãything“that“ma˜y“bGe“follo˜w˜ed“b˜y“a“v‘ÿqÇariable“of“the“appro-Ž¡‘Rpriate–€mt¸ãypGe.‘óAs“an“example,‘‹3Í\linepenalty“²and“Í\global\advance\linepenaltyŽ¡‘R²ma¸ãy–UUbšGoth“b˜e“follo•¸ãw“ed›UUb“y˜an˜¸h²in“teger˜v‘ÿqÇariable¸i².Ž¡‘aThe–‘0macros“describšGed“b˜eloš¸ãw“refer“to“the“registers“b˜y“the“names“Í\calc@A‘‘ ²andŽ¡‘RÍ\calc@B²;–UUthis“is“accomplished“bš¸ãy“Í\let²-assignmen˜ts.Ž‘RŸX-‰ffÿrŸ J=‘ "5Ÿý-:Á3ŽŽŽ‘LÜÀCoŸ'EŽ‘ãxX˜co“de˜sequence.‘U×When˜the˜scanning˜pro“cessŽ¡‘Rsees–8cthe“exclamation“pGoinš¸ãt,‘q'it“generates“an“Í\endgroup“²and“stops.‘òAs“w˜e“recallŽ¡‘Rfrom–LõSection“4,‘ŠÝthe“correct“expansion“of“a“righš¸ãt“paren˜thesis“is“\¸gµA–c̸(“µB‘€q¸gµA“¸(Ž¡‘RµB‘€q²".‘‘¾The– §remaining“tok¸ãens“of“this“expansion“are“inserted“explicitly‘ÿ*ª,‘7üexcept“thatŽ¡‘Rthe–‚hlast“assignmenš¸ãt“has“bGeen“replaced“b˜y“the“lv‘ÿqÇalue“part“(i.e.,‘ͬargumen˜t“Í#3“²ofŽ¡‘RÍ\calc@assign@generic²)›UUfollo•¸ãw“ed˜b“y˜Í\calc@B².ŽŸ‘Uüs±4Ž‘\ª®È\def\calc@assign@generic#1#2#3#4{\let\calc@A#1\let\calc@B#2%ޤ ‘Uüs±5Ž‘o‘È\expandafter\calc@open\expandafter(#4!%Ž¡‘Uüs±6Ž‘o‘È\global\calc@A\calc@B\endgroup#3\calc@B}ŽŸ‘R²(The–Š«Í\expandafter“²tokš¸ãens“allo˜w“the“user“to“use“expressions“stored“in“macros“asޤ ‘Rargumenš¸ãts–UUin“assignmen˜t“commands.)Ž©‘ó9ÞÈ\calc@assign@countŽŽ¡‘ó9Þ\calc@assign@dimenŽŽŽŽ¡¡‘÷ót\calc@assign@skipŽŽŽŽŽ‘R²W‘ÿ*ªe–©éneed“three“instances“of“the“Í\calc@assign@generic“²macro,‘¿correspGonding“toŽ¡‘Rthe–UUtš¸ãypGes“¸h²in˜teger¸i²,“¸h²dimen¸i²,“and“¸h²glue¸i².ŽŸ‘Uüs±7Ž‘\ª®È\def\calc@assign@count{\calc@assign@generic\calc@Acount\calc@Bcount}ޤ ‘Uüs±8Ž‘\ª®È\def\calc@assign@dimen{\calc@assign@generic\calc@Adimen\calc@Bdimen}Ž¡‘Uüs±9Ž‘\ª®È\def\calc@assign@skip{\calc@assign@generic\calc@Askip\calc@Bskip}ަ‘R²These–Þâmacros“eacš¸ãh“refer“to“t˜w˜o“registers,‘Eone“to“bšGe“used“globally“and“one“to“b˜eŽ© ‘Rused›UUloGcally–ÿ*ª.‘qÇW“e˜m¸ãust˜alloGcate˜these˜registers.ŽŸ‘R±10Ž‘\ª®È\newcount\calc@Acount‘,Â\newcount\calc@BcountŽ¡‘R±11Ž‘\ª®È\newdimen\calc@Adimen‘,Â\newdimen\calc@BdimenŽ¡‘R±12Ž‘\ª®È\newskip\calc@Askip‘Ÿî\newskip\calc@BskipŽŸþ6‘RÐ5.3Ž‘pÀThe–€LŸýAl‘û#×ó-2Ç@Écmbx8ØAŽŽ~/ÐT‘ý¿áŸªªEŽ‘ìSX“in terfaceŽŸuT‘R²As–')promised,‘0ewš¸ãe“rede ne“the“follo˜wing“standard“LŸýó5‘üff±AŽŽ‘͉²T‘þU>Ÿ'EŽ‘ãxX“commands:‘Z±Í\setcounter²,ަ‘RÍ\addtocounter²,–UUÍ\setlength²,“and“Í\addtolength².ŽŸ‘R±13Ž‘\ª®È\def\setcounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%Ž¡‘R±14Ž‘j×pÈ{\calc@assign@count{\global\csname‘¹–c@#1\endcsname}{#2}}}Ž¡‘R±15Ž‘\ª®È\def\addtocounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%Ž¡‘R±16Ž‘j×pÈ{\calc@assign@count{\global\advance\csname‘¹–c@#1\endcsname}{#2}}}ŽŸ‘R±17Ž‘\ª®È\DeclareRobustCommand\setlength{\calc@assign@skip}Ž¡‘R±18Ž‘\ª®È\DeclareRobustCommand\addtolength[1]{\calc@assign@skip{\advance#1}}ŽŸ‘R²(Í\setlength–UU²and“Í\addtolength“²are“robust“according“to“[2Ž‘].)ŽŸþ6‘RÐ5.4Ž‘pÀThe‘€scannerŽŸuT‘R²W‘ÿ*ªe–VVev‘ÿqÇaluate“expressions“bš¸ãy“explicit“scanning“of“c˜haracters.‘tËW‘ÿ*ªe“do“not“rely“onަ‘Ractiv•¸ãe›UUc“haracters˜for˜this.ަ‘aThe–‰scanner“consists“of“t•¸ãw“o–‰parts,‘ÖÍ\calc@pre@scan“²and“Í\calc@post@scan²;ަ‘RÍ\calc@pre@scan––²consumes“left“paren¸ãtheses,‘¦Land“Í\calc@post@scan“²consumes“bi-ަ‘Rnary–UUopGerator,“Í\real²,“Í\ratio²,“and“righš¸ãt“paren˜thesis“tok˜ens.ŽŽŸ’7ŽŽŒ‹UQ y ý£ ? ýä‘ 6È\calc@pre@scanŽŽŽ‘RÍ\calc@pre@scan– Y²reads“the“initial“part“(unš¸ãtil“some“¸h²n˜umeric¸i“²is“seen)“of“expres-ޤ ‘Rsions;‘­Áonly–åleft“parenš¸ãtheses“are“allo˜w˜ed“here,‘I¯ev˜erything“else“is“tak˜en“to“bGe“aŽ¡‘R¸h²nš¸ãumeric¸i–ûN²of“some“sort;‘Qthis“allo˜ws“unary“`Í+²'“and“unary“`Í-²'“to“bGe“treated“correctly‘ÿ*ª.Ž©‘R±19Ž‘\ª®È\def\calc@pre@scan#1{%ޤ ‘R±20Ž‘j×pÈ\ifx(#1%Ž¡‘R±21Ž‘}½ÈÈ\let\calc@next\calc@openŽ¡‘R±22Ž‘j×pÈ\elseŽ¡‘R±23Ž‘}½ÈÈ\let\calc@next\calc@numericŽ¡‘R±24Ž‘j×pÈ\fiŽ¡‘R±25Ž‘j×pÈ\calc@next#1}ŽŸ‘RÍ\calc@open–)i²is“used“when“there“is“a“left“parenš¸ãthesis“righ˜t“ahead.‘c#This“paren˜thesisޤ ‘Ris–K2replaced“b¸ãy“T‘þU>Ÿ'EŽ‘ãxX“cošGde“corresp˜onding“to“the“co˜de“sequence“\¸fŸÎ:´,‘þ¢_·!±[´BW=· ´A±]ŽŽ–"`ã¸fŸÎ:´,‘þ¢_·!±[´BW=· ´A±]ŽŽ“²"Ž¡‘Rderiv¸ãed–UUin“Section“4.‘qÇFinally‘ÿ*ª,“Í\calc@pre@scan“²is“called“again.ަ‘R±26Ž‘\ª®È\def\calc@open({\begingroup\aftergroup\calc@initBޤ ‘R±27Ž‘j×pÈ\begingroup\aftergroup\calc@initBŽ¡‘R±28Ž‘j×pÈ\calc@pre@scan}Ž¡‘R±29Ž‘\ª®È\def\calc@initB{\calc@B\calc@A}ŽŸ‘RÍ\calc@numeric–6Ųassigns“the“folloš¸ãwing“v‘ÿqÇalue“to“Í\calc@A‘6½²and“then“transfers“con˜trolޤ ‘Rto‘UUÍ\calc@post@scan².ަ‘R±30Ž‘\ª®È\def\calc@numeric{\afterassignment\calc@post@scan‘¹–\global\calc@A}ŽŸ‘f \calc@post@scanŽŽŽ‘R²The–•Vmacro“Í\calc@post@scan“²is“called“righš¸ãt“after“a“v‘ÿqÇalue“has“bGeen“read.‘1ËA˜t“thisŽ¡‘RpšGoin¸ãt,‘‡¥a–T9binary“op˜erator,‘‡¥a“sequence“of“righš¸ãt“paren˜theses,‘‡¥and“the“end-of-expressionŽ¡‘Rmark–‡¯(`Í!²')“is“allo•¸ãw“ed.‘ÕDepGending–‡¯on“our“ ndings,‘ÔEw¸ãe“call“a“suitable“macro“toŽ¡‘Rgenerate–UTthe“correspšGonding“T‘þU>Ÿ'EŽ‘ãxX“co˜de“(except“when“w¸ãe“detect“the“end-of-expressionŽ¡‘Rmarkš¸ãer:‘q[then–T}scanning“ends,‘T©and“con˜trol“is“returned“to“Í\calc@assign@generic²).Ž¡‘aThis–macro“maš¸ãy“bGe“optimized“b˜y“selecting“a“di eren˜t“order“of“Í\ifx²-tests.‘[0TheŽ¡‘Rtest–xáfor“`Í!²'‘Ük(end-of-expression)“is“placed“ rst“as“it“will“alw•¸ãa“ys–xábšGe“p˜erformed:‘¸ßthisŽ¡‘Ris–í´the“only“test“to“bšGe“p˜erformed“if“the“expression“consists“of“a“single“¸h²n¸ãumeric¸i².Ž¡‘RThis– ”ensures“that“doGcumenš¸ãts“that“do“not“use“the“extra“expressiv˜e“pGo˜w˜er“pro˜videdŽ¡‘Rbš¸ãy–UUthe“Ícalc“²pac˜k‘ÿqÇage“only“su er“a“minim˜um“slo˜wdo˜wn“in“proGcessing“time.ŽŸ‘R±31Ž‘\ª®È\def\calc@post@scan#1{%ޤ ‘R±32Ž‘j×pÈ\ifx#1!\let\calc@next\endgroup‘¹–\elseŽ¡‘R±33Ž‘o‘È\ifx#1+\let\calc@next\calc@add‘¹–\elseŽ¡‘R±34Ž‘tJœÈ\ifx#1-\let\calc@next\calc@subtract‘¹–\elseŽ¡‘R±35Ž‘y2È\ifx#1*\let\calc@next\calc@multiplyx‘¹–\elseŽ¡‘R±36Ž‘}½ÈÈ\ifx#1/\let\calc@next\calc@dividex‘¹–\elseŽ¡‘R±37Ž’‚w^È\ifx#1)\let\calc@next\calc@close–¹–\else“\calc@error#1%Ž¡‘R±38Ž’‚w^È\fiŽ¡‘R±39Ž‘}½ÈÈ\fiŽ¡‘R±40Ž‘y2È\fiŽ¡‘R±41Ž‘tJœÈ\fiŽ¡‘R±42Ž‘o‘È\fiŽ¡‘R±43Ž‘j×pÈ\fiŽ¡‘R±44Ž‘j×pÈ\calc@next}ŽŽŸ’²8ŽŽŒ‹ b¡ y ý£ ? ýä‘a²The–9xreplacemen¸ãt“cošGde“for“the“binary“op˜erators“`Í+²'“and“`Í-²'“follo¸ãw“a“commonޤ ‘Rpattern;‘_“the–±~only“di erence“is“the“tokš¸ãen“that“is“stored“a˜w˜a˜y“b˜y“Í\aftergroup².Ž¡‘RAfter–UUthis“replacemenš¸ãt“coGde,“con˜trol“is“transferred“to“Í\calc@pre@scan².Ž© K-‘R±45Ž‘\ª®È\def\calc@add{\calc@generic@add\calc@addAtoB}ޤ ‘R±46Ž‘\ª®È\def\calc@subtract{\calc@generic@add\calc@subtractAfromB}Ž¡‘R±47Ž‘\ª®È\def\calc@generic@add#1{\endgroup\global\calc@A\calc@B\endgroupŽ¡‘R±48Ž‘j×pÈ\begingroup\aftergroup#1\begingroup\aftergroup\calc@initBŽ¡‘R±49Ž‘j×pÈ\calc@pre@scan}Ž¡‘R±50Ž‘\ª®È\def\calc@addAtoB{\advance\calc@B\calc@A}Ž¡‘R±51Ž‘\ª®È\def\calc@subtractAfromB{\advance\calc@B-\calc@A}ŽŸK-‘a²The›‚¡m•¸ãultiplicativ“e˜opGerators,–Íô`Í*²'˜and˜`Í/²',“ma•¸ãy˜bGe˜follo“w“ed˜b“y˜a˜Í\real˜²or˜aޤ ‘RÍ\ratio–{B²tokš¸ãen.‘ãŽThose“con˜trol“sequences“are“not“de ned“(at“least“not“b˜y“the“ÍcalcŽ¡‘R²pac¸ãk‘ÿqÇage).ަ‘R±52Ž‘\ª®È\def\calc@multiplyx#1{\def\calc@tmp{#1}%ޤ ‘R±53Ž‘j×pÈ\ifx\calc@tmp\calc@ratio@x–¹–\let\calc@next\calc@ratio@multiply“\elseŽ¡‘R±54Ž‘y2È\ifx\calc@tmp\calc@real@x–¹–\let\calc@next\calc@real@multiply“\elseŽ¡‘R±55Ž’‡0ôÈ\let\calc@next\calc@multiplyŽ¡‘R±56Ž‘y2È\fiŽ¡‘R±57Ž‘j×pÈ\fiŽ¡‘R±58Ž‘j×pÈ\calc@next#1}Ž¡‘R±59Ž‘\ª®È\def\calc@dividex#1{\def\calc@tmp{#1}%Ž¡‘R±60Ž‘j×pÈ\ifx\calc@tmp\calc@ratio@x–¹–\let\calc@next\calc@ratio@divide“\elseŽ¡‘R±61Ž‘y2È\ifx\calc@tmp\calc@real@x–¹–\let\calc@next\calc@real@divide“\elseŽ¡‘R±62Ž’‡0ôÈ\let\calc@next\calc@divideŽ¡‘R±63Ž‘y2È\fiŽ¡‘R±64Ž‘j×pÈ\fiŽ¡‘R±65Ž‘j×pÈ\calc@next#1}Ž¡‘R±66Ž‘\ª®È\def\calc@ratio@x{\ratio}Ž¡‘R±67Ž‘\ª®È\def\calc@real@x{\real}ŽŸK-‘R²The–Spbinary“opšGerators“`Í*²'“and“`Í/²'“also“insert“co˜de“as“determined“ab˜o•¸ãv“e.‘q%Moreo“v“er,ޤ ‘Rthe–ú¯meaning“of“Í\calc@A›ú˜²and“Í\calc@B˜²is“cš¸ãhanged“as“factors“follo˜wing“a“m˜ultiplica-Ž¡‘Rtion–]and“division“opGerator“alw•¸ãa“ys›]ha“v“e˜in“teger˜t“ypGe;‘,°the˜original˜meaning˜of˜theseŽ¡‘Rmacros–UUwill“bšGe“restored“when“the“factor“has“b˜een“read“and“ev‘ÿqÇaluated.ަ‘R±68Ž‘\ª®È\def\calc@multiply{\calc@generic@multiply\calc@multiplyBbyA}ޤ ‘R±69Ž‘\ª®È\def\calc@divide{\calc@generic@multiply\calc@divideBbyA}Ž¡‘R±70Ž‘\ª®È\def\calc@generic@multiply#1{\endgroup\begingroupŽ¡‘R±71Ž‘j×pÈ\let\calc@A\calc@Acount‘¹–\let\calc@B\calc@BcountŽ¡‘R±72Ž‘j×pÈ\aftergroup#1\calc@pre@scan}Ž¡‘R±73Ž‘\ª®È\def\calc@multiplyBbyA{\multiply\calc@B\calc@Acount}Ž¡‘R±74Ž‘\ª®È\def\calc@divideBbyA{\divide\calc@B\calc@Acount}ŽŸK-‘R²Since–ƒŠthe“v‘ÿqÇalue“to“use“in“the“m¸ãultiplication/division“opGeration“is“stored“in“theޤ ‘RÍ\calc@Acount–ò$²register,‘ûthe“Í\calc@multiplyBbyA›ò ²and“Í\calc@divideBbyA˜²macrosŽ¡‘Ruse–UUthis“register.Ž¡‘aÍ\calc@close–÷x²generates“coGde“for“a“righš¸ãt“paren˜thesis“(whic˜h“w˜as“deriv˜ed“toŽ¡‘RbGe‘(\¸gµA–ºË¸(“µB›€q¸gµA“¸(“µB˜²"–(in“Section“4).‘õAAfter“this“coGde,‘Ìthe“con¸ãtrol“is“returnedŽ¡‘Rto–UîÍ\calc@post@scan“²in“order“to“loGok“for“another“righš¸ãt“paren˜thesis“or“a“binaryŽ¡‘RopGerator.ŽŽŸ’9ŽŽŒ‹ n£ y ý£ ? ýä‘R±75Ž‘\ª®È\def\calc@closeޤ ‘R±76Ž‘j×pÈ{\endgroup\global\calc@A\calc@BŽ¡‘R±77Ž‘o‘È\endgroup\global\calc@A\calc@BŽ¡‘R±78Ž‘o‘È\calc@post@scan}ŽŸþ6‘RÐ5.5Ž‘pÀCalculating–€a“ratioŽŸuT‘R²When–ºÔÍ\calc@post@scan“²encounš¸ãters“a“Í\ratio“²con˜trol“sequence,‘Ô3it“hands“con˜trolޤ ‘Rto–ÐFone“of“the“macros“Í\calc@ratio@multiply“²or“Í\calc@ratio@divide²,‘êãdepGendingŽ¡‘Ron–^wthe“preceding“cš¸ãharacter.‘-Those“macros“bGoth“forw˜ard“the“con˜trol“to“the“macroŽ¡‘RÍ\calc@ratio@evaluate²,‘ô¾whicš¸ãh–¡©pGerforms“t˜w˜o“steps:‘ o(1)“it“calculates“the“ratio,Ž¡‘Rwhicš¸ãh–ËËis“sa˜v˜ed“in“the“global“macro“tok˜en“Í\calc@the@ratio²;‘ù¤(2)“it“mak˜es“sure“thatŽ¡‘Rthe–b!v‘ÿqÇalue“of“Í\calc@B‘b²will“bGe“mš¸ãultiplied“b˜y“the“ratio“as“soGon“as“the“curren˜t“groupŽ¡‘Rends.Ž¡‘aThe–jfolloš¸ãwing“macros“call“Í\calc@ratio@evaluate“²whic˜h“m˜ultiplies“Í\calc@BŽ¡‘R²bš¸ãy–g the“ratio,‘kwbut“Í\calc@ratio@divide“² ips“the“argumen˜ts“so“that“the“`oppGosite'Ž¡‘Rfraction–UUis“actually“ev‘ÿqÇaluated.Ž©‘R±79Ž‘\ª®È\def\calc@ratio@multiply\ratio{\calc@ratio@evaluate}ŽŸ ‘R±80Ž‘\ª®È\def\calc@ratio@divide\ratio#1#2{\calc@ratio@evaluate{#2}{#1}}ŽŸ‘R²W›ÿ*ªe–V¿shall“need“t•¸ãw“o–V¿registers“for“tempGorary“usage“in“the“calculations.‘vW˜e“can“sa•¸ãv“eŽ¡‘Rone–UUregister“since“w¸ãe“can“reuse“Í\calc@Bcount².ަ‘R±81Ž‘\ª®È\let\calc@numerator=\calc@BcountŽŸ ‘R±82Ž‘\ª®È\newcount\calc@denominatorŽŸ‘R²Here–›is“the“macro“that“handles“the“actual“ev‘ÿqÇaluation“of“ratios.‘BÐThe“proGcedure“isŽ¡‘Rthis:‘‹ßFirst,‘e¤the›bat•¸ãw“o˜expressions˜are˜ev‘ÿqÇaluated˜and˜coGerced˜to˜in“tegers.‘˜ìThe˜wholeŽ¡‘RprošGcedure–9ýis“enclosed“in“a“group“to“b˜e“able“to“use“the“registers“Í\calc@numeratorŽ¡‘R²and–UUÍ\calc@denominator“²for“tempGorary“manipulations.ަ‘R±83Ž‘\ª®È\def\calc@ratio@evaluate#1#2{%ޤ ‘R±84Ž‘j×pÈ\endgroup\begingroupŽ¡‘R±85Ž‘y2È\calc@assign@dimen\calc@numerator{#1}%Ž¡‘R±86Ž‘y2È\calc@assign@dimen\calc@denominator{#2}%ŽŸ‘R²Here–Ÿìwš¸ãe“calculate“the“ratio.‘5OFirst,‘Ä4w˜e“c˜hec˜k“for“negativ˜e“n˜umerator“and/or“denom-ޤ ‘Rinator;‘Ãßnote–Ÿthat“T‘þU>Ÿ'EŽ‘ãxX“inš¸ãterprets“t˜w˜o“min˜us“signs“the“same“as“a“plus“sign.‘NÜThen,Ž¡‘Rwš¸ãe–upcalculate“the“in˜teger“part.‘ÒThe“min˜us“sign(s),‘}wthe“in˜teger“part,‘}wand“a“decimalŽ¡‘RpGoin¸ãt,–UUform“the“initial“expansion“of“the“Í\calc@the@ratio“²macro.ަ‘R±87Ž‘y2È\gdef\calc@the@ratio{}%ޤ ‘R±88Ž‘y2È\ifnum\calc@numerator<0‘¹–\calc@numerator-\calc@numeratorŽ¡‘R±89Ž’‡0ôÈ\gdef\calc@the@ratio{-}%Ž¡‘R±90Ž‘y2È\fiŽ¡‘R±91Ž‘y2È\ifnum\calc@denominator<0‘¹–\calc@denominator-\calc@denominatorŽ¡‘R±92Ž’‡0ôÈ\xdef\calc@the@ratio{\calc@the@ratio-}%Ž¡‘R±93Ž‘y2È\fiŽ¡‘R±94Ž‘y2È\calc@Acount\calc@numeratorŽ¡‘R±95Ž‘y2È\divide\calc@Acount\calc@denominatorŽ¡‘R±96Ž‘y2È\xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount.}%ŽŽŸ’þÿ²10ŽŽŒ‹ {c y ý£ ? ýä‘R²No•¸ãw›%¡w“e˜generate˜the˜digits˜after˜the˜decimal˜pGoin“t,‘Y´one˜at˜a˜time.‘â¬When˜T‘þU>Ÿ'EŽ‘ãxXޤ ‘Rscans–¿‚these“digits“(in“the“actual“m¸ãultiplication“opšGeration),‘Ú it“forms“a“ xed-p˜oin¸ãtŽ¡‘Rn•¸ãum“bšGer–„owith“16“bits“for“the“fractional“part.‘ÿW‘ÿ*ªe“hop˜e“that“six“digits“is“sucien¸ãt,Ž¡‘Revš¸ãen–UUthough“the“last“digit“ma˜y“not“bGe“rounded“correctly‘ÿ*ª.Ž©‘R±97Ž‘y2È\calc@next@digit–¹–\calc@next@digit“\calc@next@digitޤ ‘R±98Ž‘y2È\calc@next@digit–¹–\calc@next@digit“\calc@next@digitŽ¡‘R±99Ž‘j×pÈ\endgroupŽŸ‘R²No•¸ãw›K×w“e˜ha“v“e˜the˜ratio˜represen“ted˜(as˜the˜expansion˜of˜the˜global˜macroޤ ‘RÍ\calc@the@ratio²)–zèin“the“synš¸ãtax“¸h²decimal“constan˜t¸i“²[1Ž‘,‘ÄLpage“270].‘âThis“is“fedŽ¡‘Rto–}mÍ\calc@multiply@by@real“²that“will“pGerform“the“actual“m¸ãultiplication.‘êIt“isŽ¡‘RimpGortanš¸ãt–÷°that“the“m˜ultiplication“tak˜es“place“at“the“correct“grouping“lev˜el“so“thatŽ¡‘Rthe–.Æcorrect“instance“of“the“µB‘¯7²register“will“bGe“used.‘díAlso“note“that“w¸ãe“do“not“needŽ¡‘Rthe–UUÍ\aftergroup“²mec¸ãhanism“in“this“case.ަ‘N±100Ž‘j×pÈ\calc@multiply@by@real\calc@the@ratioޤ ‘N±101Ž‘j×pÈ\begingroupŽ¡‘N±102Ž‘j×pÈ\calc@post@scan}ŽŸ‘R²The–åÍ\begingroup“²inserted“bšGefore“the“Í\calc@post@scan“²will“b˜e“matcš¸ãhed“b˜y“theޤ ‘RÍ\endgroup–m@²generated“as“part“of“the“replacemenš¸ãt“of“a“subsequen˜t“binary“opGeratorŽ¡‘Ror–UUrighš¸ãt“paren˜thesis.ަ‘N±103Ž‘\ª®È\def\calc@next@digit{%ޤ ‘N±104Ž‘y2È\multiply\calc@Acount\calc@denominatorŽ¡‘N±105Ž‘y2È\advance\calc@numerator‘¹–-\calc@AcountŽ¡‘N±106Ž‘y2È\multiply\calc@numerator‘¹–10Ž¡‘N±107Ž‘y2È\calc@Acount\calc@numeratorŽ¡‘N±108Ž‘y2È\divide\calc@Acount\calc@denominatorŽ¡‘N±109Ž‘y2È\xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount}}ޤ‘R²In–rthe“follo¸ãwing“cošGde,‘<¹it“is“imp˜ortanš¸ãt“that“w˜e“ rst“assign“the“result“to“a“dimenŽŸ ‘Rregister.‘qÇOtherwise,–UUT‘þU>Ÿ'EŽ‘ãxX“wš¸ãon't“allo˜w“us“to“m˜ultiply“with“a“real“n˜um˜bGer.ަ‘N±110Ž‘\ª®È\def\calc@multiply@by@real#1{\calc@Bdimen–¹–#1\calc@B“\calc@B\calc@Bdimen}Ž¡‘R²(Note–(Othat“this“coGde“wš¸ãouldn't“w˜ork“if“Í\calc@B‘(²w˜ere“a“m˜uglue“register.‘ê´This“isޤ ‘Rthe–ZÌreal“reason“whš¸ãy“the“Ícalc“²pac˜k‘ÿqÇage“došGesn't“supp˜ort“m¸ãuglue“expressions.‘‚+T‘ÿ*ªoŽ¡‘RsuppGort–¾‚mš¸ãuglue“expressions“in“full,‘Íthe“Í\calc@multiply@by@real“²macro“m˜ustŽ¡‘Ruse–²ea“mš¸ãuglue“register“instead“of“Í\calc@Bdimen“²when“Í\calc@B‘²;²is“a“m˜uglue“register;Ž¡‘Rotherwise,‘Šýa–€Bdimen“register“should“bšGe“used.‘òSince“in¸ãteger“expressions“can“app˜earŽ¡‘Ras–Cœpart“of“a“mš¸ãuglue“expression,‘.it“w˜ould“bGe“necessary“to“determine“the“correctŽ¡‘Rregister–UUto“use“eacš¸ãh“time“a“m˜ultiplication“is“made.)ŽŸþ6‘RÐ5.6Ž‘pÀMultiplication–€bš y“real“n˜um˜b`ersŽŸuT‘R²This–==is“similar“to“the“Í\calc@ratio@evaluate“²macro“abGo•¸ãv“e,‘Bexcept–==that“it“is“con-Ž¡‘Rsiderably–UUsimpli ed“since“w¸ãe“don't“need“to“calculate“the“factor“explicitly‘ÿ*ª.ަ‘N±111Ž‘\ª®È\def\calc@real@multiply\real#1{\endgroupޤ ‘N±112Ž‘j×pÈ\calc@multiply@by@real{#1}\begingroupŽ¡‘N±113Ž‘j×pÈ\calc@post@scan}Ž¡‘N±114Ž‘\ª®È\def\calc@real@divide\real#1{\calc@ratio@evaluate{1pt}{#1pt}}ŽŽŸ’þÿ²11ŽŽŒ‹ ‡c y ý£ ? ýä‘RÌ6Ž‘jLËReps3orting‘fferrorsŽ©ç‘R²If–5Í\calc@post@scan“²reads“a“c¸ãharacter“that“is“not“one“of“`Í+²',–;`Í-²',“`Í*²',“`Í/²',“or‘5`Í)²',“anޤ ‘Rerror–Üûhas“ošGccurred,‘þäand“this“is“rep˜orted“to“the“user.‘¹Violations“in“the“syn¸ãtax“ofŽ¡‘R¸h²n¸ãumeric¸i²s–UUwill“bšGe“detected“and“rep˜orted“b¸ãy“T‘þU>Ÿ'EŽ‘ãxX.ŽŸ‘N±115Ž‘\ª®È\def\calc@error#1{%ޤ ‘N±116Ž‘j×pÈ\PackageError{calc}%Ž¡‘N±117Ž‘tJœÈ{Invalid–¹–character“`#1'“in“arithmetic“expression}%Ž¡‘N±118Ž‘tJœÈ{I–¹–expected“to“see“one“of:“+“-“*“/“)}}Ž¡‘N±119Ž‘\ª®Êhó5ùž" cmmi9É=Ñpack¾9ageŽ‘#g ÊiŽŸ!Ä‘RÌReferencesަ‘R²[1]ŽŽ‘aŽ;ó.Œ-ø cmcsc10ÙD.–ôE.“Knuth².›b ÎThe‘ü1T‘þKß'EŽ‘Í-Xb–ÿ}'o“ok‘Ãú²(Computers–°m&“T¸ãypGesetting“V‘ÿ*ªolume“A).˜Addison-ޤ ‘aŽ;W–ÿ*ªesley“,–UUReading,“Massac•¸ãh“usetts,‘UU1986.ŽŸ‘R[2]ŽŽ‘aŽ;ÙL.‘´WLampor‘ÿUTt².‘ÄaÎLŸý雑üQíó/t}\Êcmti7ÚAŽŽ‘ÙÎT‘þKß'EŽ‘Í-X,‘ÓPA‘¢ìDo–ÿ}'cument›£)Pr“ep“ar“ation˜System.‘Äa²Addison-W–ÿ*ªesley“,‘ƒýRead-Ž¡‘aŽ;ing,›UUMassac•¸ãh“usetts,˜Second˜edition˜1994/1985.ŽŽŸ’þÿ12ŽŽŒø”Õƒ’À;èyµ ó/t}\Êcmti7ó.Œ-ø cmcsc10ó-2Ç@Écmbx8ó&ÒoÇw cmss9ó%ÂÖN  cmbx12ó$ßCÊscmtt8ó#ý': cmti10ó"ßê cmmi10ó 0e—rcmmi7óKñ`y cmr10óÙ“ Rcmr7ù™}ßßßßßß