[A83] Re: Pythagorean's theorem


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

[A83] Re: Pythagorean's theorem



Matthew Marshall writes:
> Does anyone know of a good routine for Pythagorean's theorem?  I
> wrote a quick and dirty one that relied on a 1000 byte lookup table,
> but it has proven to not be accurate enough.  I suppose that I could
> do a much better job myself, but I would prefer not to reinvent the
> wheel if I do not have to.

You can do both the multiply and square root using lookup tables.  The
lookup table for 8-bit squares is 512 bytes.

The square root lookup table can also be 512 bytes.  Store 256 16-bit
numbers.  Each number is the minimum square value for the root at that
position:

[0] 0
[1] 1
[2] 4
[3] 9
...

The above table would always round down.  The table can be calculated to
round normally.  To find a square root, start at the beginning of the table.
Loop until the current number is greater than the square value.  The
previous index is the square root.

-- 
David Phillips <david@acz.org>
http://david.acz.org/




Follow-Ups: References: