previous next top contents index framed top this page unframed
The commands are summarized in Table 15–1, where An is accumulator number n, and An := An op v means to compute An op v and assign the result to An. If n is omitted, 1 is used. Thus, .+1<eol> increments the accumulator A1.
Table 15–1. Commands to Perform Arithmetic
| Command | Action |
|---|---|
| n.+v<eol> | An := An + v |
| n.-v<eol> | An := An - v |
| -n.-v<eol> | An := v - An |
| n.*v<eol> | An := An * v |
| n./v<eol> | An := An / v |
| -n./v<eol> | An := v / An |
| n.^v<eol> | An := An ^ v (raise An to the power v) |
| -n.^v<eol> | An := v ^ An (raise v to the power in An) |
| n._v<eol> | An := v (and set An's format to v's) |
| n.= | Display value of accumulator n |
| Q.= | Display values of all active accumulators |
Each of the arithmetic commands displays the new value of the affected accumulator and also puts the value displayed into the word delete buffer, so that you can recall it with the RW or .RW command. If you wish to recall the value in an accumulator, but do not know whether the value is on top of the word delete buffer, use n.= to display the accumulator and store its value on top, then RW to recall it.
MAINED prompts on the message line for v. Respond with either v<eol> or just <eol>. In the former case, the value v is to be used in the operation; in the latter, the word at the cursor is interpreted as a number, the value of which is used for v, and the cursor is positioned at the beginning of the next word as if a ) command had been issued. If v is not properly formatted, the command fails and the bell rings (this terminates a macro call).
If several numbers appear on a line separated by blanks and tabs, they may be used on successive arithmetic commands in which <eol> is specified for v.
v can specify an accumulator or a constant. An accumulator is specified as An or an where n is the accumulator number. Thus, operations can be carried out among accumulators. For example, 1.+A2<eol> performs the operation A1 := A1 + A2.
If v is a constant, it may consist of the following components in the order listed (each component is optional, although at least one component must be present):
As an alternative to an initial -, a constant can be enclosed in deficit brackets, < and >, e.g., <1.20>, or in parentheses, e.g., (1.20). These forms are often used in financial calculations to show a negative cash value.
Examples of valid constant forms are shown in Example 15–2. The numbers must be within the range supported for long real values on your computer. Section 3.4 of the MAINSAIL Language Manual gives guaranteed minimum ranges.
Example 15–2. Valid Numeric Forms for Arithmetic Commands
| 1 -5 <5> (5) 1.23 -1.23 $1 $1,234.56 -$1234.56 <$1,234,567.89> ($1,234,567.89) 123.456E12 .456E+18 |
MAINED associates format information with each accumulator to remember whether the accumulator value is to be displayed with:
Each time a command that modifies An is performed, the format information for An is updated according to v. The format information for each accumulator is cumulative. Thus, once a dollar sign is seen in a command such as n.+$1.20<eol>, An is displayed with a $ until its format is reset by means of the ._ command. On each command that modifies An, the number of fractional digits for An is set to the maximum of the current number of fractional digits for An and the number of fractional digits in v.
n._v<eol> resets the format information for An according to v. For example, if An is to be used to sum numbers, then you could type n._<$0,000.00><eol> to clear An and also set the display format for An to use deficit brackets, a dollar sign, commas, and two fractional digits with no exponent.
Macros using the arithmetic commands can be devised to add rows and columns of numbers.