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

William Astle lost at l-w.ca
Thu Feb 5 10:06:18 EST 2015


The exponentiation operator is not available under plain Color Basic. 
That functionality was added in Extended Basic. I suspect that was due 
to ROM space limitations.

On 15-02-04 10:15 PM, Arthur Flexser wrote:
> 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