4 Data Variables and Data handling
If you do not specify the form, it defaults to REAL (full) precision. Real precision variables are allotted twelve significant digits of precision. They are the most accurate form of holding numeric data but take up the most space.
The following list describes the differing characteristics of the various forms of Eloquence numeric variables. Use the form most appropriate for your own application. Once you have decided, use the declaration statements to specify the format in each program.
NOTE: Confusion can arise between the maximum size of a numeric variable, and its maximum precision. The maximum size of a numeric variable is the largest number it is able to store and is a function of the size of its exponent. The precision shows the accuracy to which the variable is held and is a function of the mantissa size. Thus a real variable may hold a number as large as 9.0 x 1099, much greater than twelve digits in decimal form, but its accuracy is still that of the mantissa.
NOTE: When an INTEGER is loaded from a program into memory is created via a calculation, it takes up to four bytes of main memory, whereas a DINTEGER takes up the same space on memory as on disk. When the INTEGER is stored it is put into two bytes of physical disk space. The DINTEGER remains 4 bytes long. So, if the INTEGER stored, does in fact take more than two bytes of main memory, it will not fit when stored and error 20 ("integer overflow") occurs. To get around this error either store the number in REAL precision, DINTEGER precision, or decrease the size of the INTEGER causing the problem.
Unless IMAGE and PRINT USING statements are used to precisely control the form of output, all numbers are output with a trailing blank and either a leading blank or a minus sign, (if the number output is negative). For more information concerningIMAGE and PRINT USING see "The PRINT Statement" on page 278.
In standard format, the most significant twelve digits of a number are output. For example, 9876543210.12345 is output as 9876543210.12. Leading and trailing zeros are suppressed. For example, 000032.100000 is output as 32.1.
Any number whose absolute value lies between 1 and 10 is output in fixed format showing all significant digits. Numbers between -1 and 1 are also output in fixed format if they can be represented precisely in 12 or fewer digits to the right of the decimal point. All other numbers are output in scientific notation. The form is the same as FLOAT 11. see "Floating Point Format" on page 87.
Here are a few examples of standard output:
FIXED number of digits
The parameter number of digits is a numeric expression, rounded to an integer, which specifies the number of digits to the right of the decimal point. Its range is from 0 to 12.
NOTE: Even if the number displayed is an integer, fixed notation adds a decimal point and the required number of trailing zeros. Similarly FIXED 12 outputs 12 places of decimals for a SHORT variable. As such a variable only extends to 6 places of decimals. The last 6 places for a short variable in FIXED 12 display are always zeros. The internal accuracy is never affected.
Here are some numbers and their FIXED 4 output form:
|Number||FIXED 4 Output|
When fixed point is set and the absolute value number to be output is >= 1E12 or has more than 17 digits, the format temporarily reverts to floating point. For example, in FIXED 12, 100000 is output as 1E+05.
FLOAT number of digits
The parameter number of digits is a numeric expression, rounded to an integer, which specifies the number of digits of precision for the mantissa (the number of digits to the right of the mantissa's decimal point). It ranges from 0 to 11.
A number output in floating point format has the form:
±d.d ... dE±dd Mantissa Exponent
|Number||FLOAT 2 Output|
Whenever a number is rounded as a result of a numeric display format, it is only the display which is affected. Internally, the number remains as accurate as the variable holding it will allow. For example, execute the lines below:
A=1.235 1.235 FIXED 2 A 1.24 FIXED 3 A 1.235The value of A does not alter, only its display.
[LET] simple variable1 [=simple variable2 . . .]=numeric expression
Notice the keyword LET is optional. For example, each of the following statements assigns the value 12 to X:
X=12 LET X = 12 X=SQR(144)As another example, the following assigns the value 12 to Y and X:
X=Y=3*4All variables are set to zero when created or when a program is run. They remain as zero until a value has been assigned to them.
To check the current value of a variable, type in its name, then press RETURN.
The values of simple variables are erased by executing a SCRATCH statement, as shown in page 25 .
10 A=1.2345678 ! REAL A implicitly defined as REAL is default 20 SHORT B 30 INTEGER C 40 B=A 50 C=A 60 PRINT "A is ";A;" B is ";B;" C is ";C 70 END RUN A is 1.2345678 B is 1.23457 C is 1In this example it is not just the display of the value that is altered. The value is permanently changed in the receiving variable. No error will be indicated in these transfers, but any attempt to assign a string value to a numeric variable (or vice versa) will not be accepted.
An array may have from one to six dimensions. Examples of one and two dimensional arrays are shown below. Arrays of three or more dimensions are not so conveniently represented on paper, but they can be set up and manipulated easily in a program.
An element is accessed by quoting its position in the array. This is done by quoting first the array name and then the subscript(s) which point to the element's position in the array. The number of subscripts which need to be quoted is the same as the number of dimensions. In a two dimensional array there will be two subscripts. It may help, to think of them as coordinates.
Subscripts are integer expressions separated by commas and enclosed in parentheses. (Any non-integer numeric value quoted as a subscript will be rounded to the nearest integer.) If a subscript is outside the range defined for an array (either too large or too small), then ERROR 17 is returned. The range of each subscript is -32767 through 32767, but the size of an array is limited by memory. The size of an array depends on both upper and lower subscript bounds.
For example, an array M dimensioned as M(2,3) is an array with two dimensions having upper bounds of 2 and 3. If the lower bound for each dimension is 0 (the default value), the array has a total of 12 elements. (As the lower bound for each dimension is 0, the total number of elements is "0..2" in the first dimension, and "0..3" in the second. There are thus 3*4 possible combinations of subscript or 12 elements in all.)
The use of columns and rows is to assist in explaining the concept of arrays, and how an element is accessed. Arrays are not held as grids within the computer, but the principle is the same.
The OPTION BASE statement is used to change the default lower bound, but the lower bound may always be defined for any array dimension by using double subscripts. The array M could also be dimensioned M(-1:1,-2:1). The upper and lower bounds are separated by a colon. Note that the number of elements is still the same; the size of array M has not altered.
M(1,0) = 10 A = M(1,0)/7 PRINT M(1,0)Since a subscript is a numeric expression evaluating to an integer, numeric expressions and variables may be used as subscripts. This allows powerful programming constructs:
30 FOR I = -2 TO 1 40 READ M(1,I) 50 NEXT IIt is thus much easier to loop through the elements of an array, when loading large amounts of data, than to use multiple INPUT statements. The larger the array, the greater the time saved.
All elements of an array can be specified collectively in an input or output operation by using the array identifier. For example:
PRINT A(*)prints the entire array A. The MAT PRINT statement is also available to print arrays, as shown in page 297 .
The maximum size of an array is specified in a DIM, COM, REAL, SHORT, INTEGER or DINTEGER statement, as shown later in this chapter. If an array is used without being explicitly defined, the default upper bound of the array is set to 10. The lower bound is either 0 or 1, depending on the OPTION BASE setting. To minimize memory waste and make your programs clearer, it is recommended that you define arrays and other variables explicitly at the start of a program.