Commodore PET User Manual page 216

Table of Contents

Advertisement

Step 2: Align the minuend and subtrahend by right-justifying both
numeric strings. This process is the same as was presented in step 2 of the" Ad-
dition via Numeric Strings" program (page 190).
30 I!LANK$="
40 X=LEN(A$):Y=LEN(B$)
50
IF
>1,
<' T ' THEN A$=LEFT$ŒLANK$ ..
'T'-~O+A$
60
IF
Y<X THEN B$=LEFT$(BLANK$,X-Y)+I!$
Step 3: For subtraction. we must determine which numeric string has a
larger value. Although the input strings may be equal in length. their values can
be quite different. For simplicity in our example. the minuend. A$. is assigned the
larger value. and the subtrahend. B$. is a smaller value. Ideally. the minuend is al-
ways the larger value. but this cannot be guaranteed.
The values of A$ and B$ are compared using the VAL function in state-
ments 65 and 70:
65 1F "iAL
0::
A$) ='.,.'AL (E:$) THEN C$=" 0" : CiOTO
1151<:1
70 IF VALO::A$»VAL(B$) GOTO 1000
If A$ is larger than B$. we have a simple subtraction problem. and the program
drops to line 1000. If B$ is larger than A$. or we are subtracting a larger number
from a smaller number. the program prepares for a negative answer.
If the subtrahend is larger than the minuend (8$ is larger than A$), the
answer will be negative. To subtract two numbers that yield a negative answer.
program a small routine to switch the contents of A$ and B$ so that the value of
A$ ,is larger than B$. Subtract B$ from A$. and the difference is C$. To make C$
negative. a negative sign. "-".
is concatenated onto the front of
C$: C$="-"+C$.
Let us subtract 5 from 3. for example. This presents a subtraction problem
where VAL(B$)
>
VAL(A$). or the subtrahend is larger than the minuend.
A$
lm
B$
[ID
Switch A$ and B$
A$
[ID
B$
@]
- +
A$
[ID
B$
@]
Subtract: VAL(A$)-VAL(B$)=C$
A$ill] - B$@]
- +
C$~
Convert to negative
C$ = "-"
+
C$
"-" +
C$
[1]
- +
C$
~
Answer:
C$
~
203

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Cbm

Table of Contents