TACL Reference Manual

UTILS:TACL Commands and Functions
HP NonStop TACL Reference Manual429513-018
8-38
COMPUTE Command
COMPUTE Command
Use the COMPUTE command to display the value of an expression.
expression
is an expression containing integer or string values and one or more operators, as
defined in Expressions on page 3-1.
Considerations
To obtain the value of an expression from within a TACL macro or routine, use the
#COMPUTE Built-In Function on page 9-71; it returns the result of the specified
arithmetic expression.
COMPUTE displays the calculation and its arithmetic result. Comparisons and
logical operators display -1 if the test is true, 0 if the test is false.
Because COMPUTE performs integer division, the fraction portion of the result is
omitted, as in 3/4 = 0.
Examples
1. This example illustrates simple use of the COMPUTE command:
6> COMPUTE 6 + 4
6 + 4 = 10
2. Equations are evaluated from left to right as indicated by the precedence for
operators. To change the order of evaluation, use parentheses:
7> COMPUTE 4 + 5 * 3
4 + 5 * 3 = 19
8> COMPUTE (4 + 5) * 3
(4 + 5) * 3 = 27
3. This example shows computations involving relational and logical expressions:
9> #PUSH oui,non
10> #SETMANY oui non, 1 0
11> COMPUTE oui < non
oui < non = 0
12> COMPUTE (non OR oui) AND NOT non
(non OR oui) AND NOT non = -1
4. This example illustrates string computations:
13> #PUSH a b
14> #SET a 1
15> #SET b 01
16> COMPUTE a=b
a=b = -1
17> COMPUTE a '=' b
a '=' b = 0
COMPUTE expression