A89: Re: Floating-point "imitation"


[Prev][Next][Index][Thread]

A89: Re: Floating-point "imitation"




Scott Noveck writes:
 > 
 > >>   mulu.w #39322,d0
 > >>   swap   d0
 > >>
 > >>The net effect is a multiply by 0.6000061, which is 0.001% off from 0.6.
 > >
 > >How exactly does this work?  I see that 65535*.6 = 39321 (not 39322?) - can

It should be 65536 * 0.6 which is 39321.6 which rounds *up*.
 
 > >I do this with any fractial value?  Say
 > 
 > Doh!  I don't know WHY I didn't see before that you're doing the exact same
 > thing I did:
 > 
 > 3    60     77    39322
 > - = --- ~= --- ~= -----
 > 5   100    128    65535

Actually, the divisor is 65536 and not 65535. 65535 is 0xffff and you
divide by 2^16 == 0x10000 when shifting right 16 times. 

But yes, I do exactly the same thing as you do but:

- I use larger numbers so the error is smaller and
- I can use swap instead of shifting to gain speed.

 > >I don't quite understand this either - if the value I want is in the upper
 > >word, then the fractional portion would be in the lower word - so wouldn't
 > >half a word ~= .5?  Wouldn't I add 32768?
 > 
 > Aha - you mean $8000, right?

Yup.
 
 > Thanks again, Zoltan - where did you learn all this stuff, anyway?

You're welcome.
Where did I learn this ? Well, I've been playing and working with 
microprocessors since '79 (the first one I touched was the 8008 !)
and actually have made a living from it since late '85.
I've read lots of books and spent a helluva lot of time in hacking
hardware and software. I should be very dumb not to acquire some
knowledge in twenty years, shouldn't I :-) 
Mind you, I was also lucky to work at a place where I was surrounded 
by a few *very* bright people who did treat me as equal (even though 
I wasn't) and instead of embarrasing me, they tought me what they knew.
The same was true for the Uni's Student Computer Center where I spent
more time than sitting in lectures :-)

Regards,

Zoltan





References: