EasyManua.ls Logo

Radio Shack TRS-80 Model III - Page 120

Radio Shack TRS-80 Model III
274 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
*
»
TRS-80
MODEL
III
Double-
to single-precision
This involves converting
a
number with
up to 17 significant
digits into
a number
with no more than
seven. BASIC chops
off (truncates) the
least significant
digits
to
produce
a seven-digit number.
Before Printing such
a
number,
BASIC
rounds it
off
(4/5
rounding)
to six digits.
Examples
A! =1.234567890124567
Stores 1 .234567 in A!
However, the statement:
PRINT
A!
will display the
value l
.23457,
because
only six digits are
displayed. The full
seven
digits are stored
in memory
.
A!=
1
.3333333333333333
Stores
1.333333 in A!.
Single-
to
double-precision
To make this
conversion,
BASIC simply
adds trailing
zeros
to the
single-precision
number. If
the original
value has
an exact
binary representation
in
single-precision
format, no
error will be
introduced.
For
example:
A#
=
1.5
Stores
l .5000000000000
in A#
,
since
1 .5 does have
an exact binary
representation
.
However,
for
numbers which
have
no exact binary
representation,
an error is
introduced
when
zeros are
added.
For example:
A#
=
1.3
Stores
1.299999952316284
in
A#.
Because
most fractional
numbers
do not
have an
exact binary
representation,
you
should
keep such
conversions
out of
your programs.
Forexample,
whenever
you
assign
a constant
value
to a double-precision
variable,
you can force the
constant
to
be
double-precision:
A#
=
1.3# A#
=
1.3D
Both store 1.3
in A#.
Here is
a special
technique for
converting
single-precision
to double-precision,
without
introducing
an error
into the
double-precision
value.
It is useful
when the
single-precision
value
is stored
in
a variable.
110

Other manuals for Radio Shack TRS-80 Model III

Related product manuals