Sharp MZ-700 Series Owner's Manual page 54

Personal computer
Hide thumbs Also See for MZ-700 Series:
Table of Contents

Advertisement

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 X 100.
1 0
A = 1 / 1 0 0 X 1 0 0
2 0
I F
A = 1
T H E N
P R I N T
" T R U E " : G O T O
4 0
3 0
P R I N T
" . F A L S E "
4 0
P R I N T
" A = "
; A
5 0
E N D
R U N
F A L S E
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
I F
A B S C A - 1 ) < . 1 E - 8
T H E N
P R I N T
" T R U E
G O T O
4 0

Advertisement

Table of Contents
loading

Table of Contents