Article View: comp.text.tex
Article #2720Re: Any ideas on fixed point addition?
From: Timothy Van Zandt
Date: Tue, 15 Sep 1992 14:56
Date: Tue, 15 Sep 1992 14:56
51 lines
1998 bytes
1998 bytes
In article <15SEP199203465090@reg.triumf.ca> asnd@reg.triumf.ca (Donald Arseneau) writes:
>In article <1992Sep14.220128.16318@Princeton.EDU>, tvz@zandtwerk.Princeton.EDU () writes...
>>Here is a macro for fixed point addition.
>>
>>USAGE \FPadd{num1}{num2}\cs
>>
>>This sets \cs to num1+num2.
>
>
>If the somewhat-limited precision of TeX's lengths is enough, how about
>
>\def\FPadd#1#2#3{\FPdim#1\p@ \advance\FPdim#2\p@
> \edef#3{\expandafter\pointless\the\FPdim}}
>
>\newdimen\FPdim
>
>\begingroup
>\catcode`P=12 \catcode`T=12
>\lowercase{
>\endgroup\def\pointless #1PT{#1}
>}
>
>The final incantation is to get pt with catcode 12 into the syntax
>of \pointless. \the gives pt with catcode 12.
>
>Donald Arseneau asnd@reg.triumf.ca
For cases where one wants the text output, rather than simply
the answer. E.g, if numbering axes, one may want
.25 .50 .75 1.00 1.25 1.50 1.75 ...
but using dimension variables gives you floating points, with
occasional rounding errors. E.g., using the method given above,
one gets:
1 + 2 = 3.0
1.05 + 2.05 = 3.1
8.10 + 3.05 = 11.15001
This last example, due to rounding errors inside TeX when converting
between sp and pt, may vary from system to system.
Tim
--
Timothy Van Zandt (609)258-4050 tvz@Princeton.EDU (NeXTMail)
Dept. of Economics, Princeton University, Princeton, NJ 08544
Technical Details
Message-ID:
<1992Sep15.145606.21328@Princeton.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!rutgers!princeton!zandtwerk.Princeton.EDU!tvzReferences:
<1992Sep14.220128.16318@Princeton.EDU> <15SEP199203465090@reg.triumf.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!rutgers!princeton!zandtwerk.Princeton.EDU!tvz From: tvz@zandtwerk.Princeton.EDU (Timothy Van Zandt) Newsgroups: comp.text.tex Subject: Re: Any ideas on fixed point addition? Message-ID: <1992Sep15.145606.21328@Princeton.EDU> Date: 15 Sep 92 14:56:06 GMT References: <1992Sep14.220128.16318@Princeton.EDU> <15SEP199203465090@reg.triumf.ca> Sender: news@Princeton.EDU (USENET News System) Organization: Princeton University Lines: 51 Nntp-Posting-Host: zandtwerk.princeton.edu