Version I.5, September 1978
With the predeclared type INTEGER the optional use of a length attribute constitutes a new type and will, in the remainder of this document, be referred to as LONG INTEGER. The LONG INTEGER is suitable for business, scientific or other applications which need extended number lengths with complete accuracy. This extension supports the four basic standard INTEGER arithmetic operations (addition, subtraction, division and multiplication) as well as routines facilitating conversion to strings and standard INTEGERs. Strong type checking is enforced throughout in the Pascal spirit. Input/Output, inline declaration of constants and inclusion in structured types are all fully supported and are analogous to the usage of standard INTEGERs.
LONG INTEGERs are declared using the standard identifier INTEGER followed by a length attribute in square brackets. This length is an unsigned number, not larger than 36, denoting the minimum number of decimal digits representable by the LONG INTEGER. For example, a variable called ‘X’ capable of storing at least an eight decimal digit signed number would be created by:
Constants are defined in the normal manner:VAR X: INTEGER[8];
In the above example RYDBERG would be by default a LONG INTEGER and could be used anywhere a LONG INTEGER could be used. In general LONG INTEGERs may be used anywhere it is syntactically correct to use REALs, however care must be taken to ensure that sufficient words have been allocated by the declared length attribute for storage of the result of assignment or arithmetic expression statements (see note in next subsection for complete details). INTEGER expressions are implicitly converted as required upon assignment to, or arithmetic operations with, a LONG INTEGER. The reverse is not true.CONST RYDBERG = 10973731;
VAR I: INTEGER; L: INTEGER[N]; { Where N is an integer constant <= 36 } S: REAL; I := L; { syntax error, see TRUNC(L) below } L := -L; { correct, with the usual exception } L := I; { always correct } L := S; { never accepted } S := L; { will be implemented with II.0 }
Arithmetic operations which may be used in conjunction with LONG INTEGERs are any or all from the set [+, -, *, DIV, unary plus/minus]. On assignment the length of the LONG INTEGER is adjusted (during execution) to the declared length attribute of the variable, therefore overflow may result. Overflow occurs only when the intermediate result exceeds the number of words required to store (as a minimum) thirty-seven decimal digits, or when the final result is assigned to a variable with insufficient length attribute. A length attribute of 5 thru 9 may store up to and including 2147483647, length attributes of 10 thru 114 may store thru 140737488355327, 15 thru 18 9223372036854775807. It is left to the interested reader to compute any larger length attribute storage capacities. This range of length attributes all having the same upper bound is a result of the allocation of a full word as the least amount of additional storage (i.e. 5 thru 9 represent a two word INTEGER.) All of the standard relational operators may be used with mixed LONG INTEGER and INTEGER. The function TRUNC(L), where ‘L’ is a LONG INTEGER, will convert ‘L’ to an INTEGER (i.e. TRUNC will accept a LONG INTEGER as well as a REAL as an argument). Overflow will result if L is greater than MAXINT.
The procedure STR(L,S) converts the INTEGER or LONG INTEGER ‘L’, into a string (complete with minus sign if needed) and places it in the STRING ‘S’. The following program segment will provide a suitable dollar and cent routine:
STR(L, S); INSERT('.', S, LENGTH(S) - 1); WRITELN(S);
where ‘L’ and ‘S’ are appropriately declared. TRUNC and STR are the only two routines which currently will accept LONG INTEGERs as parameters. An attempt to declare a LONG INTEGER in a parameter list will result in a syntax error, which may be circumvented by creating a type which is a LONG INTEGER. For example:
TYPE LONG = INTEGER[8]; PROCEDURE BIGNUMBER(BANKACCT: LONG);
The LONG INTEGER is stored as a multi-word, twos complement
binary number. System and interpreter routines do the I/O conversions
as required. Maximum storage efficiency is achieved by dynamic
expansion and contraction of word allocation as required. During
LONG INTEGER operations the length is placed on the stack above the
number itself, the declared length attribute need not be the same and
can be less than this length.