•
The symbols + and - are also used with only one operand which simply denotes
positive or negative. Symbols used
in
this way have the highest prionty
of
all
and can
only be over-ndden by the use of brackets.
Finally
if
two symbols have equal priority the leftmost operation
is
performed first so that:
PRINT
7-2
+ 5
will
cause the subtraction before the addition.
ThiS
might be important
If
you
should ever
deal with very large or very small numbers.
Data
Types,
Vanables
and
ldentihers
Operation
Symbol Examples
Results Note
Add
+
7+6.6.
13.6
Subtract
7-66
04
Multiply
*
3
*2.1
6.3
2.1
*(-3)
-6.3
Divide
7/2
35
Do not diVide by zero
-17/5
-34
•
Raise
to
power
"
4"1.5
8
Integer divide
DIV
-8
DIV 2
-4
Integers only
7 DIV 2 3 Do not divide by zero
Modulus
MOD
13
MOD 5 3
21
MOD 7
0
-17
MOD 8 7
Modulus returns the remainder part of a diVision. Any attempt to divide by zero
will
generate an error and terminate program exection.
•
Stnctly speaking, a numeric expression
is
an expression which evaluates
to
a number
and there are more possibilities than
we
need to discuss here. SuperBASIC allows you
to
do
complex things
if
you want
to
but
it
also allows you
to
do
simple things
in
simple
ways.
In
thiS
section
we
concentrate on those usual straighrtorward uses of mathematical
features.
Basically numeric expressions
in
SuperBASIC are the same as those of mathematics
but you must put the whole expression
In
the form of a sequence.
5 + 3
6 - 4
becomes
in
SuperBASIC (or other
BASIC):
(5 + 3)/(6 - 4)
In
secondary school algebra there
is
an expression for one solution of a quadratic
equation:
ax'+bx+c=O
One solution
,n
mathematical notation
is:
x =
-b
+ j
b'
-4ac
2a
If
we
start with the equation:
2x'-3x+1=0
The following program will find one solution.
100
READ
a,b,C
110
PRINT
'Root
is'
I
(-b
+SQRT<b
A
2 -
4*a*c))/(2*a)
120
DATA
2,-3,1
12/84
NUMERIC
EXPRESSIONS
Example 1
51