[A83] Re: Pythagorean's theorem
[Prev][Next][Index][Thread]
[A83] Re: Pythagorean's theorem
----- Original Message -----
From: "Matthew Marshall" <mmarshall@myrealbox.com>
To: <assembly-83@lists.ticalc.org>
Sent: Saturday, August 09, 2003 8:04 PM
Subject: [A83] Re: Pythagorean's theorem
> Good point... However, I do not only need to see which distance is greater,
> but I also need the difference between the two. (I am writing a real-time
> physics simulation implementing springs, by the way.) I think that I have
> found a good way of going at it using a 514 byte LUT. I am too tired to
> explain it tonight... maybe tomorrow.
> MWM
Here is some simplistic and slow but working integer square root
code that uses the "squares are sums of odd numbers" approach. If
I have some time I will code up a faster algorithm.
-- Norbert
;; in: HL = x, 0 <= x < 65536
;; out: HL = isqrt(x) = trunc(sqrt(x))
isqrt:
LD A, H ;
OR A, L ; x == 0 ?
JR Z, sqrtDone ; yup, result is 0
LD A, 0 ; count = 0
LD DE, 1 ; odd = 1
JR sqrtStart
sqrtLoop:
INC DE
INC DE ; odd += 2
ADD A, 1 ; count++
sqrtStart:
SBC HL, DE ; x = x - odd (i.e. original x - square)
JR NC, sqrtLoop ; while x >= square
sqrtLoopExit:
LD H, 0
LD L, A
sqrtDone:
>
> ----- Original Message -----
> From: Olof Hedman <alh@home.se>
> To: <assembly-83@lists.ticalc.org>
> Sent: Saturday, August 09, 2003 8:16 PM
> Subject: [A83] Re: Pythagorean's theorem
>
>
> > Wei Lin and Norbert Juffa and a bunch of others wrote:
> > [about calculating distances]
> >
> > Also remember that its not always necessary to do the root when you work
> > with distances.
> > If you only need to compare distances with eachother, you don't have to
> > do the root, just compare the squared distances with eachother. It will
> > give the same result.
> > Just wanted to point that out :)
> > --Olle
> >
> >
> >
> >
>
>
Follow-Ups:
References: