So we got a TRS-80 Color Computer and it came with manuals. At the age of nine I got interested in the Getting Started With Color Basic subroutines out back; in the 1982 edition anyway. These were for cosines and other functions not offered in the baseline 4-16K versions. We had a 32K Extended CoCo, so a lot of these were in fact offered in this manual's sequel. So why bother with the original?
My interest then was in how come there wasn't a SQR(-1). The "SWR" algo in the first manual seemed like it might allow it; when I duly typed this in I saw the numbers never coming to a stop. Later on of course Gleick would be mooting the Imaginary Number, which opened up plenty of other angles, but we certainly weren't taught those in the third grade.
It occurs to be that the BASIC square root function might retain some interest otherwise. There exists also a function for exponentation. Why not just... ^.5?
In the manual, what happens is iteration. It starts by setting up a value Y, which is just the input halved. Then comes the incrementor W: (x/y - y) * .5. Repeat until W=0. There is also a Z to remember the previous value of W.
This is, clearly, Newton's iterator. Why we need Z I dunno. I also get the feeling that initial Y doesn't need to be the input halved. Can we not bithack the input like q_rsqrt? That'd start with VARPTR in this tongue. Although maybe that would require we do all this in assembler.
On topic of assembler one Walter Zydhek in 1999 wrote Extended Basic Unravelled which - I trust - does what its cover promises. Behind the scenes, the CoCo was running Taylor (12) Series for the ATN function. Which looks much like what the manual's ATN was doing. The EXP also uses Taylor (8).
We find the SQR in assembler was not Newton. It just sets the exponent to .5 and then slips into the power (^) operator. Which then does the same LOG-then-EXP calc as the manual was doing. Why even offer the SQR in the first place?? /rant
One should point out further that Taylor means self-multiplication, and a lot of it. So x^2 is (much) more expensive than x*x. Honestly even Newton SQR should, generally, not be as bad as the ^.5 we're given. Hence why Q_rsqrt exists against ^-0.5.
No comments:
Post a Comment