Basic Functions; What Is A Function; The Integer Function (Int) - Commodore 128 System Manual

Hide thumbs Also See for 128:
Table of Contents

Advertisement

BASIC FUNCTIONS

What is a Function

A function is a predefined operation of the BASIC language that
generally provides you with a single value. When the function
provides the value, it is said to "return" the value. For instance,
the SQR (square) function is a mathematical function that returns
the value of a specific number when it is raised to the second
power— i.e., squared.
There are two kinds of functions:
Numeric— returns a result which is a single number.
Numeric functions range from calculating mathematical
values to specifying the numeric value of a memory location.
String—returns a result which is a character.
Following are descriptions of some of the more commonly used
functions. For a complete list of BASIC 7.0 functions see Chapter
V, BASIC 7.0 Encyclopaedia.

The INTEGER Function (INT)

What if you want to round off a number to the nearest integer?
You'll need to use INT, the integer function. The INT function
takes away everything after the decimal point. Try typing these
examples:
?
(4.25)
in t
? INT(4.75)
? INT(SQR(50))
If you want to round off to the nearest whole number, then the
second example should return a value of 5. ln fact, you should
round up any number with a decimal above 0.5. To do this, you
have to add 0.5 to the number before using the INT function, ln
this way, numbers with decimal portions above 0.5 will be
increased by 1 before being rounded down by the INT function.
Try this:
? INT(4.75+0.5)
The computer added 0.5 to 4.75 before it executed the INT
function, so that it rounded 5.25 down to 5 for the result. If you
want to round off the result of a calculation, do this:
4-20
a r r a s #
ftETtSBf
RETURN
n r n m ir

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

128d

Table of Contents