Charles Shattuck | 5 Nov 2006 20:51

Re: SEAForth questions again

I think I can answer one of your questions.  The comments around the
definition of f*f say that it is for multiplying fixed point fractions,
not integers.  These fractions are represented, according to the
comment, as follows:

ss ifff fff ffff ffff

where ss are sign bits (not sure why there are two at this point), i is
an integer, either 0 or 1, and the f's are the bits that represent a
fraction.  For example, the number $8000 would represent 1.0.  $4000
would represent 0.5.  $2000 would be 0.25.  When you multiplied 2 by 5
you were really multiplying a very small fraction by another very small
fraction, and the answer was so small that it was truncated to zero.

I added this:

: asFraction ( num den - fraction) $8000 rot rot */ ;

to help me enter fractions and watch the results of f*f.  This
definition needs to come outside the 'machine' '[' pair, it is not
machineforth.  It is used as follows:

machine
: test-f*f
   [ 1 2 asFraction ]# [ 1 2 asFraction ]# . .
   f*f test-f*f -;

You should see $4000 (0.5) pushed onto the data stack twice, and the
result of f*f is $2000, meaning 0.25.

(Continue reading)

John Drake | 6 Nov 2006 17:51
Picon
Favicon

Re: SEAForth questions again


--- Charles Shattuck <cshattuck <at> surewest.net> wrote:

> I think I can answer one of your questions.  The
> comments around the
> definition of f*f say that it is for multiplying
> fixed point fractions,
> not integers.  These fractions are represented,
> according to the
> comment, as follows:
>
> ss ifff fff ffff ffff
> 
> where ss are sign bits (not sure why there are two
> at this point), i is
> an integer, either 0 or 1, and the f's are the bits
> that represent a
> fraction.  For example, the number $8000 would
> represent 1.0.  $4000
> would represent 0.5.  $2000 would be 0.25.  When you
> multiplied 2 by 5
> you were really multiplying a very small fraction by
> another very small
> fraction, and the answer was so small that it was
> truncated to zero.

Thanks!  I guess this is another example of "when
all else fails, read (and understand) the comments."
I looked it the comp.lang.forth archives where
Jeff had explained the F21 multiply step and the
(Continue reading)


Gmane