÷ƒ’À;è 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�ŒÌtro�s3ductionŽŸç�‘RóKñ`y cmr10²Arithmetic–’in“T�‘þU>Ÿ'EŽ‘ãxX“is“done“using“lo•¸ãw-lev“el–’op�Gerations“suc�¸ãh“as“ó"ßêŸ'EŽ‘ãxX.Ž¡�‘aThe–­Ÿin x“expressions“can“b�Ge“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“ob�Gey“the“normal“scoping“rules.)‘ÎéInŽ¡�‘Rstandard–ë§L�Ÿýó5�‘üff±AŽŽ‘͉²T�‘þU>Ÿ'EŽ‘ãxX,‘;the“argumenš¸ãts“to“these“commands“m˜ust“b�Ge“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š¸ãyp�Ges.‘–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“b�Gelo˜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“do�Ges“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“b�Gene 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“corresp�GondenceŽ¡�‘Rb�Get•¸ã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“corresp�GondŽ¡�‘Rto–tvT�‘þU>Ÿ'EŽ‘ãxX's“counš¸ãt“registers;‘they“hold“quan˜tities“of“t˜yp�Ge“¸h²n˜um˜b�Ger¸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š¸ãyp�Ges“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“yp�Ge;ަ����‘a¸ŽŽŽ‘k²m•¸ãultiplication›ˆýb“y˜a˜Îr–ÿ}'e“al‘‘†²n•¸ãum“b�Ger˜(i.e.,‘±Üa˜n“um“b•Ger˜with˜a˜fractional˜part)˜can˜b“eŽ¡�‘kp�Gerformed–4Çon“a“register“of“anš¸ãy“t˜yp�Ge,‘;Jbut“the“stretc˜h“and“shrink“comp�Gonen˜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“op�Gerators“(the“tok˜ens“`Í+²',‘àw`Í-²',Ž¡�‘R`Í*²',‘Àûand–›ä`Í/²'“with“their“usual“meaning)“using“the“familiar“in x“notation;‘Ùµparen�¸ãthesesŽ¡�‘Rmaš¸ãy–bÔb�Ge“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–Þ{b�Ge“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“sp�GecialŽ¡�‘Rsynš¸ãtax;–UUsee“b�Gelo˜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“do�Gesn't“allo˜w“un˜t˜yp�Ged“constan˜ts“to“b�Ge“assigned“to“aŽ¡�‘Rdimen‘UUregister.Ž¡�‘aThe–ÂÕÍcalc“²pacš¸ãk‘ÿqÇage“also“allo˜ws“m˜ultiplication“and“division“b˜y“real“n˜um˜b�Gers.Ž¡�‘RHo•¸ãw“ev“er,‘”îa–ˆ6sp�Gecial“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“b�GeŽ¡�‘Rused–’Úfor“mš¸ãultiplication/division.‘*UThe“ rst“form“has“the“ob˜vious“meaning,‘â:andŽ¡�‘Rthe–Ùsecond“form“denotes“the“n•¸ãum“b�Ger–Ù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“comp�Gonen˜ts“of“glue“when“glue“is“m˜ultipliedŽ¡�‘Rbš¸ãy–UUa“real“n˜um˜b�Ger.‘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“b�Ge“used“to“enhance“readabilit˜y‘ÿ*ª.)Ž¡�‘aWhen–‘`T�‘þU>Ÿ'EŽ‘ãxX“p�Gerforms“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“comp�Gosite“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“b�Ger¸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“b�Ger¸iŽŽ¦��‘ah²m�¸ãultiply–UUor“divide¸iŽ���’¾cŽŽŽ’Ä1Ù!–UUÍ*�Ÿÿ±12Ž‘#�¸j“Í/�Ÿÿ±12ŽŽ¦��‘a¸h²real‘UUn•¸ãum“b�Ger¸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)“op�Gerators.‘&>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“pro�Gduct“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˜b�Ger¸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“op�Gerations“in“a“mac�¸ãhine-Ž¡�‘Rco�Gde–¹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“do�Ges“the“follo˜wingŽ¡�‘R[In•¸ãv‘ÿqÇariance›Prop�Gert“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“co�Gde“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“b�Ge“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“lo�Gcal“assignmen�¸ãt“to“the“register“on“the“lhs.Ž¡����‘a¸ŽŽŽ‘k²\��ŸÎ:´,‘þ¢_·!±[´C�}‚±]ŽŽ‘<<²"–ªïmeans“\sa•¸ãv“e–ªïthe“co�Gde“µC‘b ²unš¸ãtil“the“curren˜t“group“(scop�Ge)“ends,‘ÀUthenŽŸ �‘kexecute–UUit."‘qÇThis“corresp�Gonds“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“b�Ger¸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˜yp�Ge“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˜yp�Ge“as“the“whole“expression,‘©Ÿand“allŽ¡�‘R¸h²nš¸ãumeric¸i²s–UUin“an“¸h²in˜teger“factor¸i“²are“¸h²n˜um˜b�Ger¸i²s.Ž¡�‘aW‘ÿ*ªe›¥ha•¸ãv“e˜to˜ensure˜that˜µA˜²and˜µB‘%r²alw“a“ys˜ha“v“e˜an˜appropriate˜t“yp�Ge˜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“exp�Gected,‘w˜e“m˜ust“c˜hange“µA“²and“µBŽ¡�‘R²to–ÆBrefer“to“inš¸ãteger“t˜yp�Ge“registers.‘BW‘ÿ*ªe“can“accomplish“this“b˜y“including“instructionsŽ¡�‘Rto–acš¸ãhange“the“t˜yp�Ge“of“µA“²and“µB‘„Ò²to“in˜teger“t˜yp�Ge“as“part“of“the“replacemen˜t“co�GdeŽ¡�‘Rfor–ë`¸²;‘m5if“wš¸ãe“app�Gend“suc˜h“instructions“to“the“replacemen˜t“cošGde“describ˜ed“ab˜o•¸ãv“e,Ž¡�‘Rwš¸ãe–Çalso“ensure“that“the“t˜yp�Ge-c˜hange“is“lo�Gcal“(pro˜vided“that“the“t˜yp�Ge-c˜hangingŽ¡�‘Rinstructions–4¾only“ha•¸ãv“e–4¾lo�Gcal“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“op�Gen-group“and“close-groupŽ¡�‘Rc•¸ãharacters.‘’uThis›µ�a“v“oids˜problems˜with˜spacing˜in˜math˜(as˜p�Goin“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“b�Ge“ev‘ÿqÇaluated.Ž¡�‘aThe–”Ðthird“argumen�¸ãt“(the“lv‘ÿqÇalue)“will“b�Ge“used“as“a“pre x“to“a“register“thatŽ¡�‘Rconš¸ãtains–UUthe“v‘ÿqÇalue“of“the“sp�Geci ed“expression“(the“fourth“argumen˜t).Ž¡�‘aIn–<=general,‘tuan“lv‘ÿqÇalue“is“anš¸ãything“that“ma˜y“b�Ge“follo˜w˜ed“b˜y“a“v‘ÿqÇariable“of“the“appro-Ž¡�‘Rpriate–€mt�¸ãyp�Ge.‘ó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“p�Goinš¸ã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“b�Geen“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,‘¿corresp�Gonding“toŽ¡�‘Rthe–UUtš¸ãyp�Ges“¸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›UUlo�Gcally–ÿ*ª.‘qÇW“e˜m�¸ãust˜allo�Gcate˜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–UUop�Gerator,“Í\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“b�Ge“aŽ¡�‘R¸h²nš¸ãumeric¸i–ûN²of“some“sort;‘Qthis“allo˜ws“unary“`Í+²'“and“unary“`Í-²'“to“b�Ge“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��ŸÎ:´,‘þ¢_·!±[´B�W=· ´A±]ŽŽ–"`ã¸f��ŸÎ:´,‘þ¢_·!±[´B�W=· ´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“b�Geen“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.‘ÕDep�Gending–‡¯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“b�Ge“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“do�Gcumenš¸ãts“that“do“not“use“the“extra“expressiv˜e“p�Go˜w˜er“pro˜videdŽ¡�‘Rbš¸ãy–UUthe“Ícalc“²pac˜k‘ÿqÇage“only“su er“a“minim˜um“slo˜wdo˜wn“in“pro�Gcessing“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“co�Gde,“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˜op�Gerators,–Íô`Í*²'˜and˜`Í/²',“ma•¸ãy˜b�Ge˜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“op�Gerator“alw•¸ãa“ys›]ha“v“e˜in“teger˜t“yp�Ge;‘,°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“op�Geration“is“stored“in“theޤ �‘RÍ\calc@Acount–ò$²register,‘ûthe“Í\calc@multiplyBbyA›ò ²and“Í\calc@divideBbyA˜²macrosŽ¡�‘Ruse–UUthis“register.Ž¡�‘aÍ\calc@close–÷x²generates“co�Gde“for“a“righš¸ãt“paren˜thesis“(whic˜h“w˜as“deriv˜ed“toŽ¡�‘Rb�Ge‘�(\¸gµA–ºË¸(“µB›€q¸gµA“¸(“µB˜²"–�(in“Section“4).‘õAAfter“this“co�Gde,‘Ìthe“con�¸ãtrol“is“returnedŽ¡�‘Rto–UîÍ\calc@post@scan“²in“order“to“lo�Gok“for“another“righš¸ãt“paren˜thesis“or“a“binaryŽ¡�‘Rop�Gerator.ŽŽŸ�’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²,‘êãdep�GendingŽ¡�‘Ron–^wthe“preceding“cš¸ãharacter.‘�-Those“macros“b�Goth“forw˜ard“the“con˜trol“to“the“macroŽ¡�‘RÍ\calc@ratio@evaluate²,‘ô¾whicš¸ãh–¡©p�Gerforms“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“b�Ge“mš¸ãultiplied“b˜y“the“ratio“as“so�Gon“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“`opp�Gosite'Ž¡�‘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“temp�Gorary“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“pro�Gcedure“isŽ¡�‘Rthis:‘‹ßFirst,‘e¤the›bat•¸ãw“o˜expressions˜are˜ev‘ÿqÇaluated˜and˜co�Gerced˜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“temp�Gorary“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Ž¡�‘Rp�Goin�¸ã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˜p�Goin“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“b�Ge“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“p�Gerform“the“actual“m�¸ãultiplication.‘êIt“isŽ¡�‘Rimp�Gortanš¸ã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“b�Ge“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“op�GeratorŽ¡�‘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˜b�Ger.ަ��‘N�±110Ž‘\ª®È\def\calc@multiply@by@real#1{\calc@Bdimen–¹–#1\calc@B“\calc@B\calc@Bdimen}Ž¡�‘R²(Note–(Othat“this“co�Gde“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Ž¡�‘Rsupp�Gort–¾‚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“b�Ge“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“ab�Go•¸ã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ËRep�s3orting‘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�¸ãyp�Gesetting“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ù™}ßßßßßß