programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

- passing float to IMPORT: word

From: ForthCAD <mail_at_forthcad.com>
Date: Tue, 23 Feb 1999 11:37:12 -0000

I'm now using floats, but ...
What is the better method to pass floats parameters to a IMPORT(ED): word ?

Example...

        4 IMPORT: VectorMagnitude ( x y z -- len )

        1e 2e 3e VectorMagnitude f. ( sure its not correct ! )

....the 'C' prototype can be

float VectorMagnitude( float x, float y, float z);

....or can be

double VectorMagnitude( double x, double y, double z);

....or (rare)

double VectorMagnitude( float x, double y, float z);

The problem comes from the floating/normal stack separation.

My first solution was to convert as this:

        create sfarr 32 sfloats allot

        : n> ( n*f n -- )
>R
                R@ 0 ?DO i cells sfarr + sf! LOOP
                R> 0 ?DO i cells sfarr + @ LOOP ;

then...

        1e 2e 3e 3 n> VectorMagnitude f.

I think its not the better solution.

Charles Melice

.
Received on Tue Feb 23 1999 - 11:37:12 PST

This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:26 PST