results produced by the computer are often preventable by careful
software design. Example 4 illustrates the numerical problem that is
avoided by this quadratic-formula program.
Program
Listing:
Program
Lines:
Q01
LBL
Q
Q02
INPUT
fl
Q03
x =
0?
Q04
GTO
Q
Q05
INPUT
B
Q06
INPUT
C
Q07
x=0?
Q08
GTO
Q
Q09
RCL
B
Q10
+•-
Qll
CF
0
Q12
X<0?
Q13
SF
0
Q14
RCL
B
Q15
X*
Q16
4
Q17
RCLx
fl
Q18
RCLx
C
Q19
-
Q20
x<0?
Q21
GTO
I
Q22
SQRT
Q23
FS?
0
Q24
+/-
Q25
+
Q26
2
Q27
*
Q28
RCL*
fl
Q29
STO
X
Description:
Defines the beginning of the quadratic-
equation
routine.
Prompts for
and
stores the value of A.
If A is zero, goes back and asks for A again.
Prompts for
and
stores the value of
B.
Prompts for and stores the value of C.
If Cis zero, goesbackand asksfor all inputs
again.
Recalls
B.
-B.
Clears flag 0. (Assumes that
(—B)
is
positive.)
Is
(—B)
negative?
Sets flag 0 if it is.
Calculates
B2.
Calculates
B2 -
4AC
Tests
to see if the roots are imaginary.
Branches to imaginary routine if they are.
V(B2
- 4AQ.
Tests to see if
(—B)
is negative.
Selects
root
of
largest
absolute
value.
-B
-
V(B2
-
4AQ
or
-B
+
V(B2
-
4AQ
Calculates X of largest absolute value.
Stores value of X with largest absolute
value.
192
12:
Mathematics
Programs