>> >->  a =  sqrt ( b*b + c*c )   let's call it sentence of p...
>> >
>> [...cut...]
>> p:= max(a,b)+0.25*min(a,b)
>> [...cut...]


Erm ofcourse I meant  a:=max(b,c)+0.25*min(b,c) and it ends up like this:

|[

;    we want a=min and c=max...

    ld a,b
    cp c
    jr c,noswap

;    apparently, c<b, so we need to transfer the smallest to a and the
biggest to c

        ld a,c
        ld c,b

noswap:

;    now we know for sure that c'=max(b,c) and a=min(b,c)

    srl a
    srl a
    add a,c
    ret                ; since you use values 0-8 there will never be
overflow

]|

Note that the double srl a command actually make the factor 0.25 a little
bit smaller, coz' it's all rounded down. So you might want to add a "inc a"
inbetween the srl a commands to compensate.
If you want to visualize how good the approximation is, draw a circle with
radius 10, and then figure out for which values of b and c the algorithm
would return 10.... you will end up with an 8-sided regular polygon...
octagon if I'm not too drunk
Other values than 0.25 will also give reasonable approximations, in fact,
many values between 0.25 and 0.5 work. You should draw a picture to see what
I mean.
Anyway, it's blindingly quick.

Cas




>> Cas Cremers
>
>He - thanx a lot! Exactly what I have been searching for!
>
>greetz
>JJoS
>
>--
>Tilburg Team: Janosch, SGI, D-AX, inDark,
>               -----, SFS, Chief-Gavaman
>------------------------------------------
>I hate bugs! - I like Starship Troopers...
>
>
>
>****
>MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and
put
>in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
>quotes :-) Problems? contact [EMAIL PROTECTED]
(www.stack.nl/~wiebe/mailinglist/)
>****
>


****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****

Reply via email to