CALC


 

The CALC instruction combines multiple PL/B arithmetic operations (addition, subtraction, multiplication, division, and modulo) within a single instruction. It uses one of the following formats:

 

(1)

[label]

CALC

{dest}=({num}{op}{num}...)

(2)

[label]

CALC

{dest}={num}{op}{num}...

 

Where:

label

Optional. A Program Execution Label.

dest

Required. A Numeric Variable that receives the results of the calculation.

num

Required. A Numeric Variable or decimal constant that is the source variable in the calculation.

op

Required. One of the supported arithmetic operation types (+, -, *, /, %, **).

Flags Affected: ZERO

Note the following:

  1. CALC analyzes the mathematical equation and generates the appropriate PL/B arithmetic operations to perform the equation(s).

  2. The {num} variables or constants remain unchanged. The result of the operation(s) is placed in {dest}.

  3. Internal CALC precision is dependent upon the type of variables and literals used within the expression. Integer significance is maintained with the precision of a FORM 32 variable for all operations that do not involve a decimal point. Real significance is maintained with the precision of a FORM 32.32 variable for all operations that involve a decimal point. Take care when replacing multiple PL/B math instructions with a single CALC instruction.

  4. Any numeric constants within the equation are treated as INTEGER variables, unless they contain a decimal that designates they are a FORM variable. A numeric constant may be enclosed within double quotes.

  5.  

    CALC ANS=(1+NVAR) ;1 is treated as an INTEGER

     

    CALC ANS=(1.+NVAR) ;1 is treated as a FORM

     

  6. The arithmetic operations are performed left to right. Nesting of operations is allowed using parentheses. However, if parentheses are used in an equation, they must be balanced (an equal number of left and right parenthesis). Nested operations are performed first beginning at the lowest nesting level and working outward. The '%' operator peforms a modulo operation.
     

  7. The order of arithmetic operations in which the expressions are evaluated is determined by the precedence of the operators being used. The ordering is processed as follows:

     

    1. negation (-) unary

    2. power

    3. multiplication, division, and modulo

    4. addition and subtraction

     

  8. Only the ZERO Condition Flag is set after a CALC operation.

  9. Due to CALC's use of three operand arithmetic operations and its FORM 32.32 or FORM 32 precision, CALC generated code is not as fast as that generated in-line using two operand arithmetic operations and temporary variables only of the sizes required.

  10. Spaces may be used between operands and op codes and parentheses are not required. Therefore, any comments that are placed on the same line must be separated by some character that is not a valid operator and that cannot be the first character of a variable name.

 

 

See Also: Example Code, MOVE, Mathematical Instructions

 



PL/B Language Reference ARCTAN2 CHECK10