Float stack gymnastic

From: Charles Melice <mail_at_forthcad.com>
Date: Fri, 14 May 1999 13:19:07 +0100

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
mail_at_forthcad.com
http://www.forthcad.com

.
Received on Fri May 14 1999 - 13:19:07 PDT


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

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