Note Precautions
on
comparison
of
numeric values with BASIC 1Z-013B, numeric values
are internally represented in binary floating
point
representation; since such values
must
be converted
to
other
forms for processing
or
external display (such
as
in
decimal format with the PRINT statement), a certain
amount
of
conversion error
can occur.
For
example, when an arithmetic expression
is
evaluated whose mathematical result
is an integer, an integer value may
not
be returned
upon
completion
of
the opera-
tion
if
values
other
than integers are handled while calculations are being made.
Be
especially sure
to
take this
into
consideration when evaluating relational expres-
sions using
"="
.
This need
is
illustrated
by
the sample program below, which returns FALSE after
testing for equality between 1 and
1/100
.::!(
100.
10 A=1 / 10 0
)\(
1
00
2 0
IF
A=1 THEN
PRINT
"
TRUE
"
:GOTO
4 0
3 0
PRINT
"
FALSE
"
4 0
PRINT
"A= " ; A
5 0 END
RU
N
FA
LSE
A=1
The fact
that
both
"FALSE"
and " A = 1" are displayed
as
the result
of
this pro-
gram showns
that
external representation
of
numbers may differ from the
number
's
internal representation.
Therefore, a
better
method
of
checking for equality in the program example above
is
as
follows.
2 0
IF
ABS
C
A-1
) < .
1E-8
THEN
PRINT
"
TRUE
"
GOTO 4 0
62----
------
------------
----
--------------
--
----------
----
----
--------
-