IBM 1130 User Manual page 511

Computing system
Hide thumbs Also See for 1130:
Table of Contents

Advertisement

Section
Subsections
Page
70
10
I
20
03
Rounding
Suppose you have just calculated an employee
I
s gross
pay as 107/\5673. (understood to be $107.5673) and
wish to apply a deduction of $19.733 (represented as
19,,733.). Notice that the decimal points are not
"lined up"; the units are not the same--the gross is
in hundredths of cents, and the deductions are· in
tenths of cents.
How do you perform this subtraction?
a. 107,,5673. - (19,,733. x 10.)
b.
(107,,5673. /10.) - 19,,733.
c.
(107,,5673./10000.) - (19,,733./1000.)
None of these is correct. Before subtracting, you
must round these two quantities -- commonly to the
nearest cent.
In the case of the 107,,5673. gross, you must add
1/2 cent or 50. hundredths, obtaining 107,,5723. ,
then divide by 100, to get 107,,57.23. Now, since
the. 23 is both inexact and meaningless, it must be
eliminated. The WHOLE function supplied with the
Commercial Subroutine Package converts the
fractional part of the number to zeros.
All three functions-- round, shift and clear
fractions -- can be done in one statement. The
statement
GROSS
=
WHOLE «GROSS +
5~. )*~.
01+0. 5)
rounds off GROSS, shifts it two places to the right,
and clears everything remaining to the right of the
decimal point to zeros. Note that multiplication
rather than division was used (see Section 70.50.00).
In the case of the deduction, you would say
DEDUC
=
WHOLE «DEDUC +5.) *0.1+0.5)
Now both values have been rounded and are in whole
cents, with all extraneous fractions cleared. Note
what would have happened if the fractions had not
been cleared:
10757.23
1973.80
8783.43
The correct answer is:
10757.00000
1973.00000
8784.00000
You may wish to code several arithmetic statement
functions, each one shifting a predetermined number
of places to the right:
RND1(X)
=
WHOLE (X+X/ ABS(X)*5. 0)/10. +0.5)
RND2(X)
=
WHOLE «X+X/ ABS(X)*50. 0)/100. +0. 5)
RND3(X)
=
WHOLE «X+X/ ABS(X)*500. 0)/1000. +0.5)
etc.
where the fourth character of the FUNCTION
name indicates the number of places to be shifted.
Accuracy and Magnitude
Suppose you are using extended precision real
numbers, where 31 bits are available for the whole
number and fraction combined. How
large a number
can you have? 2,14.7, 4S:3 ,6.47?N().,
th~.tis
just
the largest number that can fit in 31 bits. Values
much larger are possible-- for example,
1,000,000,000,000,666,777,888., which can easily
be handled in the 1130.
The decimal point indicator can be as large as
64 in binary, or about 38 in decimal, meaning
that extremely large real numbers can be repre-
sented on the 1130.
The drawback is their accuracy. Especially in
commercial applications, numbers must be precise.
Thenumber 1,000,000,000,000,666,777,888. can be
read into the 1130, but it will be accurate only to
nine or ten decimal digits. In other words, the nine
most significant digits will be retained, but the re-
maining digits will be lost. The decimal point indi-
cator will show the proper magnitude, but the
number is not accurate.
If
you want accurate results, you must not exceed
the 31 bits (2,147,483,647.) or 23 bits (8,388,607.)
available.
Furthermore,
if
you want accurate numbers, you
must not allow any fractions to be generated.
Combining the above two warnings, then, means
that you should limit real numerical values to the
whole numbers between -2,147,483,648. and
+2,147,483,647. Any number outside this range
will probably not be exact; most fractions will
probably be inexact.
If
you work commercial problems in cents, you
are limited to $21,474,836.47 (carried as a whole,
fixed point real number). The limit is $2,147,483.647
if
you wish to work in mills.
These limits are usually ample for jobs such as
payroll, etc., but may be troublesome in
accmmting-type work, where year-to-date sales,
total assets, etc., may exceed $21 million.
If
this
is the case, the decimal arithmetic subroutines of
the 1130 Commercial Subroutine Package may be
used.

Advertisement

Table of Contents
loading

Table of Contents