F;

Performs arithmetic calculations such as addition, subtraction, multiplication and division, using a stack of operands.

Syntax

F;element{;element}...;?[P|ref]

Syntax elements

element operators and operands to be processed.

?P moves the result of the calculation (top of the stack) into the parameter pointed to by the buffer pointer in the primary input buffer.

?refmoves the result of the calculation (top of the stack) to the location specified by ref, a direct or indirect reference to a buffer or select register.

Operands

ref A direct or indirect reference to a buffer or select register that contains the value to be placed on the stack.

{C}n Places the literal numeric value specified by n on the stack.

Operators

_ Reverses the top two stack entries.

The following operators each remove the top two entries from the stack, performs the specified calculation and returns the result to the top of the stack.

+ Adds the top two stack entries.

- Subtracts the entry from the top of the stack from the second stack entry. Note that this is similar to the FS English conversion.

* Multiplies the top two stack entries.

/ Divides the second entry by the entry from the top of the stack. Note that this is the opposite of English.

R Divides the second entry by the entry from the top of the stack and returns the remainder.

Operation

This command uses a stack processor similar to the one used by the F conversion code in English.

The F; command is processed from left to right.

Each operand pushes a value onto the stack.

Each operator removes the top two entries from the stack, performs the specified calculation and returns the result to the top of the stack.

The stack holds up to 23 entries and can be visualized as follows:

Top of stack → Stack 1
  Stack 2
  Stack 3
  .
.
.

 

The result of the calculation can be moved into any of the Proc buffers using a question mark (?) operator at the end of the function command.

Comments

The English stack processor (F conversion) works in reverse - the top stack value is used as the first operand. Proc is similar to the FS English conversion. Refer to English Reference for more information about English stack arithmetic.

Example

In the following example, the command is:

F;C20;%4;*;?%2

PIB Before

PIB After

XXX^322^ABCD^3^44

XXX^60^ABCD^3^44

This example can be visualized as follows:

 

C20

%4

*

?%2

Top of stack →

20

3

60

 

 

 

20

 

 

 

  1. The first element (C20) places the value 20 on top of the stack.
  2. The next element (%4) places the value in the 4th parameter of the PIB (3) on top of the stack.
  3. The next element (*) multiplies the top two values on the stack, deletes them and puts the result, which is 60, on top of the stack.
  4. The last element, (?%2) moves the result (60) to the 2nd parameter of the PIB, overwriting the old value.