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

Arthur Flexser flexser at fiu.edu
Thu Feb 5 13:08:13 EST 2015


Right.  I had taken a quick look at the dispatch table for Color Basic
functions and had seen that exponentiation was included.  But I now see
that the jump address leads only to ?SN ERROR unless you have Extended
Basic.

Art

On Thu, Feb 5, 2015 at 10:06 AM, William Astle <lost at l-w.ca> wrote:

> 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
>>>
>>>
>>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list