Appendix
A:
Subroutines
Subroutines
listed
in
this
Appendix:
Square Root
Exponentiation
Logarithms
(Natural and Common)
Exponential (Powers of e)
Tangent
Cosine
Sine
ArcCosine
ArcSine
ArcTangent
Sign
Square
Root
Computes: SQR(X),
*TX~
Input:
X, must be greater than or
equal
to
zero
Output: Y
-
Also uses: W,Z internally
Other
subroutines
required:
None
How
to call:
GOSUB
3(903(9
These
subroutines
will let
you
run
programs
which
require advanced math
functions
not
directly
available
in LEVEL
I
BASIC.
If
you entered
all
the
subroutines exactly
as
they're
listed, you'd have less
than
700
bytes
of memory left
for
your main
program
—
not
enough
to do
much of anything.
So just
enter
the
subroutines
you need, and
omit
REM
statements if
you're
still short on space.
Once you've entered a subroutine and gotten it running, save it on a
Cassette.
Try saving different combinations of subroutines on Cassettes: for
example,
make a SIN/COS/TAN
cassette, a
SIN/SQR cassette,
an EXPO-
NENTIATION/LOG/EXPONENTIAL/SGN
cassette
-
whatever
combina-
tions are useful to
you.
Each subroutine listing has a set of instructions in the
margin.
Study
them
closely. You'll see that some subroutines require other subroutines for in-
ternal calculations. You must
enter
these
"auxiliary subroutines" when
the
instructions call for them.
Always
enter
30000
END as a protective block when using subroutines. For
complete
information
on the use of subroutines, see Chapter
25.
NOTE:
Accuracy
of the
subroutines
is
less than
the
accuracy of
LEVEL I
math operators
and intrinsic functions.
This
is due to two
factors:
1.
The
subroutines
contain many chain
calculations, which
tend
to
magnify the small error
of
individual
operations. 2.
These
subroutines are
only approximations of
the functions they replace. In general, the sub-
routines are accurate to five or six decimal places over much of their allowable range,
with a decrease in accuracy as
the
input
approaches
the
upper
or lower
limits for input
values.
30000
END
30010
REM *SOUARE ROOT* INPUT X, OUTPUT Y
30020
REM ALSO USES
W
&
Z
INTERNALLY
30030
IF
X
=
T. Y
=
: RET,
30040 IF X>0 T.
30060
30050
P. "ROOT OF NEGATIVE NUMBER?"
: STOP
30060 Y=X* .5 : Z
=
30070
W=(X/Y-Y!*.5
300 80 IF
{ W
=
0)
+ tW=Z
)
T.
RET.
30090 Y=Y+W : Z=W : G.
30070
216