Re: Float stack gymnastic

From: <Aa7qb_at_aol.com>
Date: Sun, 16 May 1999 03:49:59 EDT

In a message dated 14-May-99 6:13:16 AM US Mountain Standard Time,
sftalk_at_forth.com writes:

>
> My own preference (which I think I stole from John Wavrik) is to add one
> more level of indirection (as I did in my big number routines, where
> it was an absolute must).
>
> : (*) ( addr1 addr2 -- addr3)
>
> where the addrs are the addresses where the vectors are stored.
>
> 1) This cuts down on the stack thrashing.
> 2) It provides a common way of handling all sorts of objects and operators.
> -LenZ-
>
> SF Talk wrote:
> >
> > Date: Fri, 14 May 1999 13:19:07 +0100
> > From: "Charles Melice" <mail_at_forthcad.com>
> > Subject: Float stack gymnastic
> >
> > What is the more efficient sequence to define the following math word ?
> >
> > : (*) ( n: x y z u v w -- a b c )
> > ...the stack gymnastic... ;
> >
> > The explicit computation (dot product) is given by the simple formulas:
> >
> > a = y*w - v*z
> > b = z*u - w*x
> > c = x*v - u*y
> >
> > My 'trivial' solution was to write the following:
> >
> > \ private
> > fvariable x fvariable y fvariable z
> > fvariable u fvariable v fvariable w
> >
> > \ public
> > : (*) ( n: x y z u v w -- a b c )
> > w f! v f! u f!
> > z f! y f! x f!
> > y f@ w f@ f* v f@ z f@ f* f- \ n: a
> > z f@ u f@ f* w f@ x f@ f* f- \ n: b
> > x f@ v f@ f* u f@ y f@ f* f- \ n: c
> > ;
> >
> > But it would be nicer to write the following and have a optimal result...
> >
> > : (*) ( n: x y z u v w -- a b c )
> > a = y*w - v*z
> > b = z*u - w*x
> > c = x*v - u*y
> > ;
> >
> > Any idea ?
> >
> > ________
> > Charles Melice
>
It seems so unForth like to be declaring all of these variables and in
addition, using floating point arithmetic. It's possible to pick and roll
your way through the calculations but it looks horrible. That is still the
way I would do it. I personally avoid variables like the plague.

BTW, I played around with big numbers for the first time and I do like them.
Being a card player, I always want to calculate 52 things taken 13 or some
such at a time. I just used brute force to provide a fast and easy way to do
this type of calculation. It is a real memory grabber but with the memory
available in modern personal computers, who cares?

The method I used was as follow:

BIG 1 DUP DUP CONSTANT 0! CONSTANT 1!
BIG 2 BIG* DUP CONSTANT 2!
BIG 3 BIG* DUP CONSTANT 3!
                       .
                       .
                       .
BIG 52 BIG* CONSTANT 52!

Then for the combinations, again brute force, I simply entered:

52! 13! BIG/ 39! BIG/ DUP CONSTANT 52C13 CONSTANT 52C39

Boy, talk about unForth like but it is fast and of course has no round off
errors ... like I really need 12 significant digits or even more :)

.
Received on Sun May 16 1999 - 03:49:59 PDT


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 09-Feb-2012. Archive updated nightly.