<< Click to Display Table of Contents >> Navigation: User guide > Arithmetic > Table arithmetic |
Table arithmetic is used with MT (manip table) commands to set one or more table cells to a value. Individual table cells may also be set with an arithmetic expression
This is a special form of arithmetic which repeats the same actions for one or more sets of table cells. For example, you could add two similar tables together and put the result in a third table. The arithmetic is performed on each cell from each table in the expression in turn and the result stored in the relevant cell in the table being defined.
A table arithmetic consists of one or more of the following:
table
part-id
wconstant
wvar
ivar
svar
field
cell
combined with the operators:
+ plus
* multiplied
- minus
/ divide
IMPORTANT: CL always evaluates table arithmetic from left to right.
Parentheses can not be used in table arithmetic to control the order of evaluation.
If any tables or part-ids occur in table arithmetic, they must all contain the same number of cells.
If a cell appears in the expression, all tables and part-ids must consist of one cell only. If you wish to use a cell for the whole thing, put the value into a wvar first.
If two or more consecutive part-ids refer to the same table in table arithmetic, there is no need to repeat the table name.
Table arithmetic is carried out on a cell by cell basis, so for example:
mt #3 = #1 + #2,
adds cell 1 of table 1 to cell 1 of table 2 and stores the value in cell 1 of table 3, cell 2 of table 1 to cell 2 of table 2 stored in cell 2 of table 3, and so on.
If a variable or constant appears in table arithmetic, it is treated as if it were a table of the appropriate size, each cell containing the value of the variable or constant, so for example:
mt #1 = #1 * 2,
multiplies every cell of table 1 by 2.
A cell of a table may be "undefined". This value is represented in code by the letter U. Normally this occurs when the cell is the product of a division by zero. It can occur in statistics tables where the base for calculation is zero. If any part of a table arithmetic expression is undefined for a given cell, then the whole value is regarded as undefined for that cell. This can cause cells defined by such table arithmetic to take value U.
Note that U, by itself, is valid table arithmetic, as is any wconstant by itself.
VERY IMPORTANT: do not attempt to increment a table in a later tables stage that has the value U anywhere in it. The results are unpredictable.
A cell may be set to contain text, see %TEX function.
VERY IMPORTANT: do not attempt to increment a table in a later tables stage that has %TEX values stored in it, nor should you use it in further MT commands except %TEX. The results are unpredictable.
Examples of table arithmetic:
45,
#47,
#6(R7),
#34/#35*100.0,
#105(R1)+(R2)+(R3),
#12A - 100.0 + #I2 * 45.0 / #WALL + 983.88,