Re: SEAForth questions again

John Drake <[email protected]>
Newsgroups gmane.comp.lang.forth.colorforth
Message-ID <[email protected]>

--- Charles Shattuck <[email protected]> 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
updated t18 multiply step.  Using that I came
up with this code.

: 8*8 ( n1 n2 -- n1*n2 )  \ 16 bit output
  push 2* 2* .  \ left shift n1 8 times
    2* 2* 2* .
    2* 2* 2* .
    pop +* +* +*
    +* +* +* +*
    +* push drop .
    pop ; 

Now I get the expected results and I get them
MUCH faster.
 
> 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.
> 
> I assume f*f is only defined in the ROM for the
> cores with A/D and D/A
> is because it will be useful for scaling A/D inputs.

Yeah, that makes sense.

> As to how you would multiply the integers in your
> matrix example, I
> don't have an easy answer to that yet, but I'll work
> on.
> 
> Charley.

Well, all I needed was to realize I was barking up
the wrong tree. [:)]  The matrix multiplication
now works.

http://www.quartus.net/twiki/pub/Main/VentureForth/MATRIX.F

I'm sure it needs a lot of polishing.  I've also
started a VentureForth page at the Quartus Wiki.
Not much there now.

http://www.quartus.net/cgi-bin/twiki/view/Main/VentureForth

Regards,

John M. Drake



 
____________________________________________________________________________________
Sponsored Link

Get an Online or Campus degree
Associate's, Bachelor's, or Master's - in less than one year.
http://www.findtherightschool.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.