At 4:36 PM +0100 14-03-00, [EMAIL PROTECTED] wrote:
>I would think that you would be able to use a table that holds the values for
>the whole distance equation.  Since range for a and b are both [0..255], the
>range for (a-b) is -255 to +255 and you can make a 512 element table to hold
>the values.

Right, we could do that.  But then you've only optimized out a 16-bit
multiply operation, and added in the table lookup.  That's probably going
to be a little faster, because multiply can be pretty bad, but I doubt it
would make a really big difference.  (With the lookup, you'd have to be
computing offsets and reading from RAM or ROM for the table, which takes up
some of the time you're saving.)

>PS: Shouldn't the mentioned equation be (a-b)^2 = a^2 - 2ab + b^2?

Yep.  Oops.  :-)

                                --Bob

P.S.

At 4:38 PM +0100 14-03-00, Brandon Wallace wrote:
>But it is way more than 512 outcomes.  It is more like
>
>256+255+254+...+1 = 128*257=32896 values
>
>or there about...

Combinatorics?  Nope. 255-2 is identical to 254-1.  :-)

That is, (a-b) can only have 511 possible values, because both a and b are
in the range [0..255].  The result has to be in the range [-255..255],
which is just 511 distinct values.

An interesting puzzle:  why 511 and not 512?  What happened to the missing
value??

The *result* can be in the range [0*0..255*255], or [0..65025], but only
511 values (the even squares) in this range are used.  But note that 65025
is too large to represent as a signed 16-bit value, and (a-b) can be
negative, so you need a signed value to hold that.  Use two variables?
Does that blow register allocation?  Who says writing optimal C code is
easy!




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to