🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text.tex
Article #2740

Re: Any ideas on fixed point addition?

#2740
From: David Carlisle
Date: Tue, 15 Sep 1992 08:53
67 lines
2582 bytes
>>>>> On 14 Sep 92 22:01:28 GMT, tvz@zandtwerk.Princeton.EDU said:

tvz> Here is a macro for fixed point addition.

tvz> USAGE \FPadd{num1}{num2}\cs

tvz> This sets \cs to num1+num2.

tvz> Rules:

tvz>   num1 and num2 should have the same number of digits to the
tvz>     right of the decimal. (Exception: if num1 is an integer,
tvz>     decimal not needed.)
tvz>   num1 and num2 should have at least one digit to the left
tvz>     of the decimal (e.g., 0)
tvz>   num1 and num2 can have at most 8 digits on each side of the
tvz>     decimal.
tvz>   Negative numbers are OK.

tvz> DOES ANYONE HAVE ANY BETTER IDEAS? IT SEEMS LIKE A LOT OF
tvz> WORK FOR SOMETHING SO SIMPLE!!

tvz> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tvz>     
tvz>  
.......[70 lines deleted]....   

tvz> \FPadd{-13.42}{3.33}\tempa

tvz> \message{***\tempa***}

tvz> \bye
tvz> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

tvz> Tim
tvz> -- 
tvz> Timothy Van Zandt   (609)258-4050  tvz@Princeton.EDU (NeXTMail)
tvz> Dept. of Economics,  Princeton University,  Princeton, NJ 08544

You can use dimen registers for floating point arithmetic, then you do
not have any restrictions then on the number of decimal digits of each
number, except of course that you must be within the range of a valid
dimen. 


\def\myFPadd#1#2#3{%
\dimen0=#1pt
\advance\dimen0 by #2pt
\edef#3{\expandafter\STRIP\the\dimen0}}
{\catcode`\p=12 \catcode`\t=12
\gdef\STRIP#1pt{#1}}
 
\myFPadd{-13.42}{3.33}\tempa

\message{***\tempa***}
\bye
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--
                           David Carlisle
                                    JANET: carlisle@uk.ac.man.cs

                                    Computer Science Department
                                    Manchester University
                                    Oxford Road
                                    Manchester
                                    England
                                    M13 9PL
Technical Details
Message-ID: <CARLISLE.92Sep15095358@r8d.cs.man.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!mucs!m1!carlisle
References: <1992Sep14.220128.16318@Princeton.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!mucs!m1!carlisle
From: carlisle@cs.man.ac.uk (David Carlisle)
Newsgroups: comp.text.tex
Subject: Re: Any ideas on fixed point addition?
Message-ID: <CARLISLE.92Sep15095358@r8d.cs.man.ac.uk>
Date: 15 Sep 92 08:53:58 GMT
References: <1992Sep14.220128.16318@Princeton.EDU>
Sender: news@cs.man.ac.uk
Organization: Department of Computer Science, University of Manchester
Lines: 67
In-reply-to: tvz@zandtwerk.Princeton.EDU's message of 14 Sep 92 22:01:28 GMT