; TeX output 1997.03.06:1733soDtGGcmr17The7tGGcmss17trigq:pacqkage!", cmsy10XQ cmr12DarvidCarlislepScarlisle@cs.man.ac.uk&37 1994/10/16:ōINff cmbx121aLIntros3ductionIK`y cmr10TheseGfmacrosimplementthetrigonometricfunctions,}csin,cosGfandtan.Ineachcase Itwolcommandsarede ned.F*orinstancethecommand'ExXxorplainTU>'EXcountersmaybGeused.0InTU>'ExXBookIsyntax,UUargumentsmustbGeoftypGe:q !", cmsy10h': cmti10optional.vsigns!iHڕhfactoriXSomeUUotherexamplesare:I\CalculateSin{22.5},UU\UseTan{\value{mycounter}},\UseCos{\count@}.XNotethatunliketheps gmacros,thesesaveallpreviouslycomputedvqalues.IThisQcouldeasilybGechanged,RbutIQthoughtthatinmanyapplicationsonewouldIwantmanyinstancesofthesamevqalue.(egrotatingalltheheadingsofatableIbyUUthesameamount).XIdon't=reallylikethisneedtopre-calculatethevqalues,IoriginallyimplementedI\UseSinTsothatitautomaticallycalculatedthevqalueifitwasnotpre-stored.1ThisIworkedN neintesting,P+untilINremembGeredwhyoneneedsthesevqalues.oY*ouwantItoibGeabletosay\dimen2=\UseSin{30}\dimen0.MWhichmeansthat\UseSinImustUUexp}'and]޲toahfactori%w.!čI2aLTheffMacrosLs1S" cmsy9h#ow cmss9pack9age#g i3PߤN cmtt9\nin@ty"\@clxx"\@lxxib\@mmmmlxviiiISomeUUusefulconstantsforconvertingbGetweendegreesandradians.?<$ȠJ b> cmmi10'ןwfe (֍180"%'<$355Kwfe*8 (֍11381802-z=<$L71Kwfe (֍4068^Ls2S\chardef\nin@ty=90 Ls3S\chardef\@clxx=180Ls4S\chardef\@lxxi=71Ls5S\mathchardef\@mmmmlxviii=4068I&effr @ -:q% cmsy6L|{Ycmr8ThisX lehasvÎersionnumb'ExXtokens,@asthecoGecientsareallrational.C'kVsinx't(x)'l̵x8(1=3!)x3S+(1=5!)x5(1=7!)x7+(1=9!)x9g'<$((((7!=9!x^2S87!=7!)x^2+7!=5!)x^2+7!=3!)x^2+7!=1!)xwfeLy (֍n®7!þ=<$((((1=72x^2S81)x^2+42)x^2+840)x^2+5040)xwfeąV (֍XB5040ITheanestedformusedabGoveareducesthenumberaofoperationsrequired.QInorderItoKfurtherreducethenumbGerKofoperations,andmoreimportantlyreducetheInumbGer'oftokensused,0wecanprecomputethecoGecients.bNotethatwecannotIuseUU9!asthedenominatorasthiswouldcauseover owofTU>'ExX'sarithmetic.積y\@coeffzy\@coeffay\@coeffby\@coeffcy\@coeffdISaveUUthecoGecientsas\(math)chars. sՍLs6S\chardef\@coeffz=72 Ls7S%\chardef\@coefa=1Ls8S\chardef\@coefb=42Ls9S\mathchardef\@coefc=840I10S\mathchardef\@coefd=5040[~\TG@rem@ptIThey standardtrickofgettingarealnumbGeroutofahdimenci&.(Thisgivesamax- Iimumaccuracyofapprox.5decimalplaces,whichshouldbGesucient.ItputsaIspaceUUafterthenumbGer,UUperhapsitshouldn't.I11S{\catcode`t=12\catcode`p=12\gdef\noPT#1pt{#1}} I12S\def\TG@rem@pt#1{\expandafter\noPT\the#1\space}[~y\TG@termIComputevonetermoftheabGovevnestedseries.+Multiplytheprevioussumbyx^2I(storedUUin\@tempb,thenaddthenextcoGecient,#1.I13S\def\TG@term#1{% I14XdD\dimen@\@tempb\dimen@I15XdD\advance\dimen@#1\p@}[~\TG@seriesIComputetheabGoveseries.gthevqalueindegreeswillbein\dimen@beforethisis Icalled.I16S\def\TG@series{%I17XdD\dimen@\@lxxi\dimen@I18XdD\divide\dimen@\@mmmmlxviiisՍI\dimen@1nowcontainstheangleinradians,8asahdimenci&QJ.eW*eneedtoremovethe Iunits,UUsostorethesamevqalueasahfactori(̲in\@tempa.I19XdD\edef\@tempa{\TG@rem@pt\dimen@}%INowUUputx^2Ȳin\dimen@and\@tempb.I20XdD\dimen@\@tempa\dimen@ I21XdD\edef\@tempb{\TG@rem@pt\dimen@}%ITheUU rstcoGecientis1=72.I22XdD\divide\dimen@\@coeffz I23XdD\advance\dimen@\m@ne\p@I24XdD\TG@term\@coefbI25XdD\TG@term{-\@coefc}%I26XdD\TG@term\@coefd2 soINowUUthecubicinx^2Ȳiscompleted,soweneedtomultiplybyxanddivideby7!.I27XdD\dimen@\@tempa\dimen@ I28XdD\divide\dimen@\@coefd}\CalculateSinIIfUthisanglehasalreadybGeencomputed,"donothing,elsestoretheangle,andcall I\TG@@sin.I29S\def\CalculateSin#1{{%I30]\expandafter\ifx\csnamesin(\number#1)\endcsname\relaxI31f\dimen@=#1\p@\TG@@sinI32f\expandafter\xdef\csnamesin(\number#1)\endcsnameI33{\TG@rem@pt\dimen@}%I34]\fi}}\CalculateCosIAsUUabGove,butusetherelationcos(x)=sin6(908x).I35S\def\CalculateCos#1{{%I36]\expandafter\ifx\csnamecos(\number#1)\endcsname\relaxI37f\dimen@=\nin@ty\p@I38f\advance\dimen@-#1\p@I39f\TG@@sinI40f\expandafter\xdef\csnamecos(\number#1)\endcsnameI41}\{\TG@rem@pt\dimen@}%I42]\fi}}\TG@reduceIRepGeatedlyuseoneofthetherelatationssin(x)U=sin(180qx)U=sin(180qx) ItoUUgetxintherange90x90.qThenUUcall\TG@series.I43S\def\TG@reduce#1#2{%I44S\dimen@#1#2\nin@ty\p@I45]\advance\dimen@#2-\@clxx\p@I46]\dimen@-\dimen@I47]\TG@@sin}y\TG@@sinISlightlyUUcryptic,butitseemstowork...I48S\def\TG@@sin{%I49]\ifdim\TG@reduce>+%I50]\else\ifdim\TG@reduce<-%I51]\else\TG@series\fi\fi}%3P\UseSin 3P\UseCosIUseUUapre-computedvqalue.I52S\def\UseSin#1{\csnamesin(\number#1)\endcsname}I53S\def\UseCos#1{\csnamecos(\number#1)\endcsname}XAUUfewshortcutstosaveUUspace.I54S\chardef\z@num\z@I55S\expandafter\let\csnamesin(0)\endcsname\z@numI56S\expandafter\let\csnamecos(0)\endcsname\@neI57S\expandafter\let\csnamesin(90)\endcsname\@neI58S\expandafter\let\csnamecos(90)\endcsname\z@numI59S\expandafter\let\csnamesin(-90)\endcsname\m@neI60S\expandafter\let\csnamecos(-90)\endcsname\z@numI61S\expandafter\let\csnamesin(180)\endcsname\z@numI62S\expandafter\let\csnamecos(180)\endcsname\m@ne3so\CalculateTanIOriginallyIcoGdedtheT*aylorseriesfortan,butitseemstobemoreaccurateto Ijust1Ztaketheratioofthesineandcosine.Thisisaccurateto4decimalplacesIforanglesupto50^,ߎafterthattheaccuracytailso ,giving57.47894insteadofI57.2900UUfor89^.I63S\def\CalculateTan#1{{% I64]\expandafter\ifx\csnametan(\number#1)\endcsname\relaxI65f\CalculateSin{#1}%I66f\CalculateCos{#1}%I67f\@tempdima\UseCos{#1}\p@I68f\divide\@tempdima\@ivI69f\@tempdimb\UseSin{#1}\p@I70f\@tempdimb\two@fourteen\@tempdimbI71f\divide\@tempdimb\@tempdimaI72f\expandafter\xdef\csnametan(\number#1)\endcsnameI73{\TG@rem@pt\@tempdimb}%I74]\fi}}3P\UseTanIJustUUlike\UseSin.I75S\def\UseTan#1{\csnametan(\number#1)\endcsname}\two@fourteen ,`\@ivItwoUUconstantsneededtokeepthedivisionwithinTU>'ExX'srange.I76S\mathchardef\two@fourteen=16384 I77S\chardef\@iv=4XPrede neUUtan(90)UUtobGeanerror.I78S\expandafter\def\csnametan(90)\endcsname{\errmessage{Infinitetan!}} I79S\expandafter\let\csnametan(-90)\expandafter\endcsnameI80 \csnametan(90)\endcsnameI81Sh!5" cmmi9=pack9age#g i4#; #ow cmss9" cmsy9!5" cmmi9ߤN cmtt9': cmti10 cmmi10K`y cmr10ٓRcmr7*f