Chapter
14
The
INTEGER
function
Integer??? "I can't even
pronounce it, let
alone
understand
it."
Oh, come, come.
Don't let
old
nightmares
of being trapped
in Algebra class
stop you
now.
It's pronounced (in-teh-jur)
and simply means a whole
number like
1,
or
2 or
3,
etc.
How
difficult can
that
be? Come
to
think
of it, some folks
make a whole career
of
complicating
simple
ideas. We're here
to
do just the opposite.
The INTEGER
function,
INT(X), allows
us
to "round off"
any number,
large
or small,
positive or negative, into an integer, or whole
number.
Type
NEW to
clear
out any old programs,
then
enter:
30
X
=
3.
14159
40
Y
=
INT(X)
50
PR
INT " Y
=
"
(
Y
... and
RUN.
The
display reads
Y
=
3
Oh
—
success is so sweet!
It rounded 3.14159
off
to 3. Change line
30
to read:
30
X
= -3.
14159
$z
"CAll IT? INTEGER OF COURSE!"
Careful
—
we're
not
talking about
ordinary
round-
ing
(what could
be ordinary
about your
Computer?!).
Ordinary
rouadirigigiyes
us
the
closest whole
number,
whether
it's
larger
or smaller than
X.
INT(X),
on the other
taand*.gives
us
the largest
whole
number which is
less than
or equal
to
X, Ass-
yon
?|1
see
In this chapter,
this is
a
very versatile
':'';':
form: of
rounding
—
in fact,
you
can use
it
topro^
:.
dace the
other, "ordinary"
kind
of
rounding.
;
;
... and
RUN.
Good Grief! It rounded
the answer down to read
Y
=
-4
What kind of
rounding
is
this?
Easy. The INT function always
rounds
DOWN
to
the
next
lowest WHOLE
number.
Pretty
hard to get that
confused!
It
makes
a positive number
less
positive,
and makes a
negative
number
more negative
(same
thing
as less
positive).
At
least
it's
consistent.
m
I
X
B
NOTE:
LEYEL1
BASIC
allows the
1NT(X) func-
tion
to work only, with numbers
larger
than
-32767
and smaller than +32767.
LEVEL
2
;
BASICremoves this restriction. Use
of
a
value
of;
X outside
this
range causes the Computer
to
halt
execution and
ask
HOW? ,.
'-
'''.-.
,M.
69