[Coco] Color BASIC SQR(2) or 2^0.5

Arthur Flexser flexser at fiu.edu
Thu Feb 5 00:15:15 EST 2015


That's a pretty opaque algorithm, apparently designed to work under an
integer-only Basic.

As far as I can tell, X^0.5 should be a legal expression under Color Basic,
so you shouldn't need to do anything at all to approximate it.

Or, you could use Newton's approximation method:

10000 REM X=SQR(N)
10010 X0=1 'first approximation
10020 X=(X0+N/X0)*.5   'next approximation
10000 IF ABS(N-X*X) < .0000001 THEN RETURN
10030 X0=X:GOTO 10020

Art



On Wed, Feb 4, 2015 at 11:32 PM, Melanie and John Mark Mobley <
johnmarkmelanie at gmail.com> wrote:

> If you need a SQR function for the 1980 4K CoCo Programming Challenge try
> the code below.
> This is a successive approximation SQR subroutine.
>
> 10000 REM Y=SQR(X)
> 10010 K=0
> 10020 J=4294967296
> 10030 FOR I=1 TO 32
> 10040 K=K+J
> 10050 Y=K/65536
> 10060 IF Y*Y>X THEN K=K-J
> 10070 J=J/2
> 10080 NEXT I
> 10090 Y=K/65536
> 10100 RETURN
>
> John Mark Mobley
>
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list