• Keine Ergebnisse gefunden

Floating Point Arithmetic

Im Dokument The Computer Concepts (Seite 167-174)

Scientific and engineering computations frequently involve lengthy and complex calculations in which it is necessary to perform arithmetic opera-tions on numbers that may vary widely in magnitude. To obtain a meaningful answer, problems of this type usually require that as many significant digits as possible be retained during calculation and that the decimal point always be properly located. When such problems are applied to a computer, several factors must be taken into considera-tion, the most important of which is the decimal point location.

Generally speaking, a computer does not recognize the decimal point present in any quantity used during a calculation. Thus a product of 414154 will result regardless of whether the factors are 9.37 X 44.2,93.7 X 0.442, or 937. X 4.42, and so forth. It is the programmer's responsibility to be cognizant of the decimal point location before and after the cal-culation and to arrange the program accordingly. For example, in an addition operation, the decimal point of all numbers in the operation must be lined up to obtain the correct sum. Therefore, the programmer must guarantee this arrangement by shifting the quantities as they are added.

Example:

xxx

.XXXXX • A

.XXXXXXXX • B

X. XXXXXXX • C

where A

+

B

+

C ~ 999 148

Floa~g Point Arithmetic 149 Program to calculate A + B + C

BNF *+24,B

SF B-3

A A,B-3

BNF *+24,C

SF C-2

A A,C-2

If the program were

A A,B

A A,C

the result would not be accurate (except by chance) since the decimal points are not properly aligned.

All of the digits in all of the data are not used in the first (correct) solution to the problem, but under the statement of the problem, there is little choice in the matter.

Another course might be to define an ll-digit field of zeros, symbolic-ally called "Zeros," and produce the following program:

A ZEROS-3,A

BNF *+36,ZEROS-3

CF ZEROS-3

SF ZEROS-l

A ZEROS-I,C

BNF *+36,ZEROS-l

CF ZEROS-I

SF ZEROS

A ZEROS,B

However, the only portion of the answer that has mathematical foundation is the portion "Zeros-IO" through "Zeros-3" inclusive. The significant difference is that the first program ignored the possibility of carries whereas this program extends itself to propagate those carries into position "Zeros-3."

150 Floating Point Arithmetic It is conceivable, though, that when numbers that vary greatly in magnitude are manipulated, the resulting quantity could exceed prac-tical working limits.

The processing of numbers expressed in ordinary form (for example, 427.93456, 0.0009762, 5382., -623.147, 3.1415927, etc.) can be accom-plished on a computer only with extensive analysis to determine the size and range of intermediate and final results. When programmed, this analysis and subsequent number scaling will frequently require a larger percentage of the total time needed to solve the problem than will the actual calculation. Furthermore, number scaling requires com-plete and accurate information regarding the bounds on the magnitude of all numbers that come into the computation (input, intermediate re-sults, output). Since it is not always possible to predict the magnitude of all numbers in a given calculation, analysis and number scaling is sometimes impractical.

To alleviate this programming problem, a system must be employed in which information regarding the magnitude of all numbers accom-panies the quantities in the calculation. That is, if all numbers are represented in some standard predetermined format which instructs the computer in an orderly and simple fashion as to the location of the decimal point, and if this representation is acceptable to a computer, then quantities that range from minute fractions having many decimal places to large whole numbers having many integer places may all be handled with ease.

The arithmetic system most commonly used, in which all numbers are expressed in a format having the above features, is called "floating point arithmetic." Specialized programs that handle floating point numbers are called "floating point subroutines." The notation used in floating point arithmetic is basically an adaptation of the scientific nota-tion widely used today. In scientific work, very large or very small numbers are expressed as a number between .1 and .99 ... , times a power of lO. That is, the decimal point of all numbers is placed to the left of the high-order (leftmost) nonzero digit. Hence, all quantities may be thought of as a decimal fraction times a power of 10 (for example, 427.93456 as 0.42793456 X 103 and 0.0009762 as 0.9762 X lO-3) where the fraction is called the "mantissa" and the power of 10, used to indicate the number of places the decimal point was shifted, is called the "char-acteristic." In addition to the advantages of uniformity inherent in scientific notation, the use of floating point numbers during processing eliminates the necessity of analyzing operations to determine the position of the decimal point in intermediate and final results since the decimal point is always immediately to the left of the high-order digit in the mantissa.

Floating Point Arithmetic 151 In the 1620 floating point arithmetic system, each quantity is ex-pressed as an n digit number (4 """ n """ 47) consisting of a 2-digit char-acteristic and an (n-2)-digit fractional mantissa. This fraction, in absolute value, may extend between 0.100 ... 00 and 0.999 ... 99. This is shown in Figure 12.1.

xxx ...

XXXXX

... .,~

in c

Fig. 12.1. Form of a Floating Point Number.

In Figure 12.1, c represents the characteristic and m the mantissa, as explained below. The original number is m X lOc•

The mantissa (m), or fractional part of the number, consists of the leftmost (n-2) digits of the floating point number. The decimal point is always tacitly assumed to lie immediately to the left of the high-order mantissa digit. The sign of the original number is always associated with the mantissa and is designated by the presence (for negative) or absence (positive) of a flag in the units position of the mantissa. A mantissa is called "normal" or "normalized" when its high-order digit is nonzero. In 1620 floating point, the mantissa must always be normal-ized. The floating point subroutines always leave normalized floating point numbers as the result of a floating point operation, with one ex-ception. The exception to the "normalized mantissa rule" is a floating point zero which is always expressed as 0.000 ... 00 with a characteristic of -99.

The characteristic (c) represents the power of 10 used to specify the location of the decimal point in the original number. It stands for the number of places the decimal point was shifted in order to place it to the left of the high-order, nonzero digit. The direction of the shift is determined by the sign of the characteristic. Thus, if the sign of the characteristic is negative, the decimal point was shifted to the right the number of positions specified by the characteristic. If no sign is indicated-the absence of sign specifying a positive characteristic-the shift was to the left. Thus, the characteristic can assume a range of values from -99 to 99, inclusive,

-99"""c"""99.

Upon combining the ranges and the mantissa and characteristic, we see that floating point numbers may lie within the range

±0.100 ... 00 X 10-99 to ±0.999 ... 99 X 1099 •

In floating point form, both the characteristic and mantissa are always flagged over their respective high-order digits to indicate the

end-of-152 Floating Point Arithmetic field condition. Table 12.1 demonstrates the conversion of numbers in ordinary form to 1620 variable-size floating point notation.

Table 12.1

FLOATING POINT

NUMBER NORMALIZED MANTISSA SIZE FORM

123.4567~ 0.12345678 X 103 8 digits r234567803 0.00765432 0.765432 X 10-2 6 digits 76543202 0.00765432 0765432 X 10-2 10 digits 7654320000020 - 0.1234987623 - 0.1234987623, X 100 13 digits r234987623000000 - 0.1234987623 - 0.1234987623 X 100 3 digits 1230000

- 0.00001 - 0.1 X 10-4 2 digits 10040 - 0.00001 - 0.1 X 10-4 8 digits 10000000040

-0.0 - 0.0 X 100 4 digits OOOOm}0

0.0 0.0 X 100 4 digits 0000'990

• Low-order zeros added to increase mantissa size to desired length .

•• Mantissa truncated to reduce size to desired· length.

GENERAL NOTES ON 1620 FLOATING POINT SUBROUTINES In the 1620 floating point subroutines, an attempt to generate a characteristic of magnitude greater than 99 creates a condition called

"characteristic overflow." An attempt to generate a characteristic less than -99 creates a condition called "characteristic underflow." Should either of these conditions be generated as a result of an arithmetic operation, the programmer will be provided with a choice of two options as follows:

OVERFLOW

1. Program Halt or

2. The floating point number 99 ... 9999 is placed in

the result field and the program continues.

Floating Point Arithmetic

o ~ Halt R [ Store

o

Nines in W Result Field

Halt

1

UNDERFLOW Store Zeros in Result Field

o

1

Fig. 12.2. Overflow-Underflow Schematic.

UNDERFLOW

1. Program Halt

2. The floating point number or 00 ... 0099 is placed in the result field and the program continues.

153

These options function independently of each other. Thus it is possible to halt on an underflow and place 9's in the result field on an overflow. The converse is also true. The detection of an overflow or underflow condition will cause the subroutine being executed to examine core position 00401 to determine the course of action. The programmer must make manual or programmed provisions for one of the four conditions in order to exercise his option.

GENERAL NOTES ON THE USE OF FLOATING POINT ARITHMETIC

During any floating point calculation the size of the two operands must be identical. Thus, it is not possible to "floating add" a 17-digit floating point number and an 8-digit floating point number.

Another form of floating point assumes a fixed word size of lO digits consisting of a 2-digit characteristic and an 8-digit mantissa. The char-acteristic precedes the mantissa and a notation called "excess fifty" is employed. Excess fifty implies that the number 50 is added to the

154 Floating Point Arithmetic characteristic developed. Thus, the characteristic may assume values between 00 and 99 only. In this fashion, the number 25.3 (0.253 X 102 )

becomes 5225300000 in floating point form. Similarly, the number -0.0000001 (-0.1 X 10-6 ) becomes 4410000000. This notation has been widely used in a great variety of decimal computers but does not lend itself well to variable-word-size floating point.

Problems

I: Convert the following numbers to floating point notation. The number in parentheses is the mantissa size desired.

1. 15.96(9) 2. - 50073. (12) 3. 10128.965(4) 4. - 8.9(15) 5. 0.127(5)

6. - 0.00001589(6) 7. - 0.0(12) 8. - 0.001248(4) 9. 183.72(10) 10. 0.00000001 (7)

II. Convert the following numbers to their fixed point representation. Use sufficient digits to fully express the number: 100000 is to be expressed as 0.1000 not as 0.1.

1. 53807 2. 956121703

s.

1721520:2 4. 810219312 5. 6100 6. 7522128I1 7. IUllllnI 8. 21134190I 9. 611600 10. 151719121810

Chapter 13

Im Dokument The Computer Concepts (Seite 167-174)