CA Dataquery evaluates arithmetic expressions according to the arithmetic operator it finds. This standard processing sequence is called the hierarchy of operations and is performed in the following order.
CA Dataquery evaluates expressions within parentheses first. When expressions are contained within nested parentheses, evaluation proceeds from the least inclusive (innermost) to the most inclusive (outermost) set.
When the order of consecutive operations on the same hierarchic level is not completely specified, the order of operation is left-to-right; for example, the following two expressions are evaluated the same.
A + B / C - D / C * F + G * C / H + I
A + (B/C) - ((D / C) * F) + ((G * C) / H) + I
Note: There must be a one-to-one correspondence between left and right parentheses in an arithmetic expression.
Sample
The result of an arithmetic expression is dependent on the precision of the result and the arithmetic operation which is performed. The following example illustrates how CA Dataquery calculates the value for FLDX, using the following expression.
FLDX (3.3) = ((2. + 3) * (4 + (5 / 6 + (7 - 8)))) + 9
Explanation
The following chart shows the hierarchy of operations, the part of the expression which is evaluated in each step, and the result of that evaluation. After each step, we show the expression with the value from the just completed step replacing the part that was evaluated.
|
Step |
Part |
Result |
Comments |
|---|---|---|---|
|
1 |
(7 - 8) |
-1 |
CA Dataquery evaluates the innermost parenthetical expression first. |
|
|
|
FLDX (3.3) = ((2. + 3) * (4 + (5 / 6 + (-1)))) + 9 |
|
|
2 |
5 / 6 |
0.833 |
CA Dataquery evaluates the part of the inner parenthetical expression involving division, since division has a higher precedence than addition. |
|
|
|
FLDX (3.3) = ((2. + 3) * (4 + (0.833 + (-1)))) + 9 |
|
|
3 |
(0.833 + (-1)) |
-.167 |
CA Dataquery uses the results from the evaluation in Steps 1 and 2 to evaluate the second innermost parenthetical expression. |
|
|
|
FLDX (3.3) = ((2. + 3) * (4 + (-.167))) + 9 |
|
|
4 |
(2 + 3) |
5 |
The two remaining inner parenthetical expressions both involve addition and are at the same level, so CA Dataquery evaluates the left expression first. |
|
|
|
FLDX (3.3) = ((5) * (4 + (-.167))) + 9 |
|
|
5 |
(4 + (-.167)) |
3.833 |
CA Dataquery evaluates the inner parenthetical expression on the right. |
|
|
|
FLDX (3.3) = (5 * 3.833) + 9 |
|
|
6 |
(5 * 3.833) |
19.165 |
CA Dataquery completes the evaluation of the multilevel parenthetical expression by multiplying the values within parentheses of FLDX, (3.3), designates the number of digits CA Dataquery calculates on either side of the decimal point. The precision (3.3) indicates that the value has three digits to the left and right of the decimal point. |
|
|
|
FLDX (3.3) = 28.165 |
|
You can also define FLDX with a precision different from (3.3), as in the following alternative formats:
FLDX (7.5) = +0000028.16665 FLDX (2.4) = +28.1665 FLDX (2.0) = +28 FLDX (1.0) = ***E3*** (Display indicates error because of overflow.)
|
Copyright © 2014 CA.
All rights reserved.
|
|