8 FLOATING POINT ARITHMETIC PACKAGE

This section describes the BCD floating point (FP) package that is resident in the OS ROM in both the models 400 and 800.

The floating point package maintains numbers internally as 6-byte quantities: a 5-byte (10 BCD digit) mantissa with a 1-byte exponent. BCD internal representation was chosen So that decimal division would not lead to the rounding errors typically found in binary representation implementations.

The package provides the following operations:

ASCII to FP conversion.
FP to ASCII conversion.
Integer to FP conversion.
FP to integer conversion.
FP add, subtract, multiply, and divide.
FP logarithm, exponentiation, and polynomial evaluation.
FP zero, load, store, and move.

A floating point operation is performed by calling one of the provided routines (each at a fixed address in ROM) after having set one or more floating point pseudo registers in RAM. The result of the desired operation will also involve floating point pseudo registers. The primary pseudo registers are described below and their addresses given within the square brackets:









IMPLEMENTATION DETAILS

Floating point numbers are maintained intatnallg as 6-bute qvantitiesi with 5 bgtes (10 BCD digits) of mantissa and 1 byte af exponent. The mantissa is alwags normalized such that the most significant byte is nonzero (note "byte" and not "BCD digit").

The most significant bit of the exponent byte provides the sign for the mantissa: 0 for positive and 1 for negative. The remaining 7 bits of the exponent byte provide the exponent in excess 64 notation. The resulting number represents powers of 100 decimal (not powers of 10). This storage format allows the mantissa to hold 10 BCD digits when the value of the exponent is an even power of10, and 9 BCD digits when the value of the exponent is an odd power of 10.

The implied decimal point is always to the immediate right of the first byte. An exponent less than 64 indicates a number less than 1. An exponent equal to or greater than 64 represents a number equal to or greater than 1.

Zero is represented by a zero mantissa and a zero exponent. To test for a result from any of the standard routines; test either the exponent or the first mantissa byte for zero.

The absolute value of floating point numbers must be greater than 10**-98, and less than l0**+98, or be equal to zero. There is perfect symmetry between positive and negative numbers with the exception that negative zero is never generated.

The precision of all computations is maintained at 9 or 10 decimal digits but accuracy is somewhat less for those functions involving polynomial approximations (logarithm and exponentiation). Also, the problems inherent in all floating point systems are present here, for example: subtracting two very nearly equal numbers, adding numbers of disparate magnitude or successions of any operation will all result in a loss of significant digits. An analysis of the data range and the order of evaluation of expressions may be required for some types of applications.

The examples below compare floating point numbers with their internal representations, as an aid to understanding storage format. All numbers prior to this point have been expressed in decimal notation but these examples will use hexadecimal notation. Note that 64 decimal (the excess number of the exponent) is 40 when expressed in hexadecimal.

Number  +0.02 = 2 * 10**-2 = 2 * 100**-1
Stored: 3F 02 00 00 00 00  (FP exponent = 40  1)

Number: -0.02 = -2 * 10**-2 = -2 * 100**-1
Stored: BF 02 00 00 00 00  (FP exponent = 80 + 40  1)

Number: +37.0 = 3. 7 *  10**1= 37 * 100**0
Stored: 40 37 00 00 00 00  (FP exponent = 40 + 0)

Number: -4.60312486 *  10**11 = -46.03... * 100**5
Stored: C5 46 03 01 24 86  (FP exponent = 80 + 40 + 5)

Number: 0.0
Stored: 00 00 00 00 00 00  (special case)