Results of arithmetic operations
After any necessary conversion of the operands in an expression has been carried out, the arithmetic operation is performed and a result is obtained. This result can be the value of the expression, or it can be an intermediate result upon which further operations are to be performed, or a condition can be raised.
Table 1 and Table 2 show the attributes and precisions that result from various arithmetic operations.
Table 1 shows the attributes of the result for the special cases of exponentiation noted in the right-hand columns of Table 1 and Table 2.
In an add or subtract of FIXED(p1,q1) and FIXED(p2,q2), ABS(q1-q2) must be less than or equal to N for DECIMAL and M for BINARY.
In a multiply or divide of FIXED(p1,q1) and FIXED(p2,q2), the resulting scale factor must be between 0 and 127.
If both operands in an addition, multiplication or division are UNSIGNED FIXED BIN, then the result also has the UNSIGNED attribute.
On the z/OS platform, the choice of which set of instructions is used for a float calculation is determined by two compiler options:
- Under FLOAT(DFP)
- All computations that would yield a FLOAT DEC result are done using the IEEE decimal floating-point instructions.
- All computations that would yield a FLOAT BIN result are done using the floating-point instructions for the format specified by the HEXADEC and IEEE suboptions of the DEFAULT compiler option.
- Under FLOAT(NODFP)
- All computations that would yield a FLOAT result are done using the floating-point instructions for the format specified by the HEXADEC and IEEE suboptions of the DEFAULT compiler option.
So, under the FLOAT(NODFP) and DEFAULT(HEXADEC) options, all computations are done using the hexadecimal floating-point instructions, and variables declared IEEE will be converted to HEXADEC. But, under the FLOAT(NODFP) and DEFAULT(IEEE) options, all computations are done using the IEEE binary floating-point instructions, and variables declared HEXADEC will be converted to IEEE as necessary.
On all other platforms, float calculations are done using the IEEE binary floating-point instructions native to that platform.
Under the compiler option RULES(ANS), if one operand is scaled FIXED DECIMAL and the other is FIXED BINARY, the FIXED BINARY value is converted to FIXED DECIMAL. Table 3 shows the attributes and precisions that result for this case under compiler option RULES(ANS). For more information about the RULES compiler option, see the Programming Guide.
| 1st Operand
(p1,q1) |
2nd Operand
(p2,q2) |
Attributes of
the Result for Addition, Subtraction, Multiplication, or Division |
Addition
or Subtraction Precision |
Multiplication
Precision |
Division
Precision |
Attributes
of the Result for Exponentiation |
|---|---|---|---|---|---|---|
| FLOAT
DECIMAL (p1) |
FLOAT
DECIMAL (p2) |
FLOAT
DECIMAL (p) |
p = MAX(p1,p2)
|
FLOAT
DECIMAL (p) (unless special case C applies) p = MAX(p1,p2) |
||
| FLOAT
DECIMAL (p1) |
FIXED
DECIMAL (p2,q2) |
|||||
| FIXED
DECIMAL (p1,q1) |
FLOAT
DECIMAL (p2) |
|||||
| FLOAT
BINARY (p1) |
FLOAT
BINARY (p2) |
FLOAT
BINARY (p) |
FLOAT
BINARY (p) (unless special case C applies) p = MAX(p1,p2) |
|||
| FLOAT
BINARY (p1) |
FIXED
BINARY (p2,q2) |
|||||
| FIXED
BINARY (p1,q1) |
FLOAT
BINARY (p2) |
|||||
| FIXED
DECIMAL (p1,q1) |
FLOAT
BINARY (p2) |
FLOAT
BINARY (p) |
p = MAX(
CEIL(p1*3.32),p2) |
FLOAT
BINARY (p) (unless special case A or C applies) p = MAX( CEIL(p1*3.32),p2) |
||
| FLOAT
DECIMAL (p1) |
FIXED
BIN (p2,q2) |
|||||
| FLOAT
DECIMAL (p1) |
FLOAT
BINARY (p2) |
|||||
| FIXED
BINARY (p1,q1) |
FLOAT
DECIMAL (p2) |
FLOAT
BINARY (p) |
p = MAX(p1,CEIL(p2*3.32))
|
FLOAT
BINARY (p) (unless special case B or C applies) p = MAX( p1,CEIL(p2*3.32)) |
||
| FLOAT
BINARY (p1) |
FIXED
DECIMAL (p2,q2) |
|||||
| FLOAT
BINARY (p1) |
FLOAT
DECIMAL (p2) |
|||||
| 1st Operand
(p1,q1) |
2nd Operand
(p2,q2) |
Attributes of
the Result for Addition, Subtraction, Multiplication, or Division |
Addition
or Subtraction Precision |
Multiplication
Precision |
Division
Precision |
Attributes
of the Result for Exponentiation |
|---|---|---|---|---|---|---|
| FIXED
DECIMAL (p1,0) |
FIXED
DECIMAL (p2,0) |
FIXED
DECIMAL (p,q) |
p = 1
+MAX(p1,p2) q = 0 |
p = 1
+p1+p2 q = 0 |
p = N
q = N-p1 |
FLOAT DECIMAL (p)
(unless special case A applies) p = MAX(p1,p2) |
| FIXED
BINARY (p1,0) |
FIXED
BINARY (p2,0) |
FIXED
BINARY (p,0) |
p = 1
+MAX(p1-q1, p2-q2) +q q = 0 |
p = 1+p1
+p2 q = 0 |
p = M
q = 0 |
FLOAT BINARY (p)
(unless special case B applies) p = MAX(p1,p2) |
| FIXED
DECIMAL (p1,0) |
FIXED
BINARY (p2,0) |
FIXED
BINARY (p,0) |
p = 1
+MAX(r,p2) q = 0 |
p = 1
+r+p2 q = 0 |
p = M
q = 0 |
FLOAT BINARY (p)
(unless special case A applies) p = MAX(CEIL (p1*3.32 ),p2) |
| FIXED
BINARY (p1,0) |
FIXED
DECIMAL (p2,0) |
FIXED
BINARY (p,0) |
p = 1
+MAX(p1,t) q = 0 |
p = 1
+p1+t q = 0 |
p = M
q = 0 |
FLOAT BINARY (p)
(unless special case B applies) p = MAX(CEIL (p1*3.32 ),p2) |
| M is the maximum precision for FIXED BINARY.
N is the maximum precision for FIXED DECIMAL. r = 1 + CEIL(p1*3.32) s = CEIL(ABS(q1*3.32)) * SIGN(q1) |
t = 1 + CEIL(p2*3.32)
u = CEIL(ABS(q2*3.32)) * SIGN(q2) v = CEIL(p2/3.32) w = CEIL(p1/3.32) |
|||||
| 1st Operand
(p1,q1) |
2nd Operand
(p2,q2) |
Attributes of
the Result for Addition, Subtraction, Multiplication, or Division |
Addition
or Subtraction Precision |
Multiplication
Precision |
Division
Precision |
Attributes
of the Result for Exponentiation |
|---|---|---|---|---|---|---|
| FIXED
DECIMAL (p1,q1) |
FIXED
DECIMAL (p2,q2) |
FIXED
DECIMAL (p,q) |
p = 1 +
MAX(p1-q1, p2-q2) +q q = MAX(q1,q2) |
p = 1
+p1+p2 q = q1+q2 |
p = N
q = N-p1+q1-q2 |
FLOAT DECIMAL (p)
(unless special case A applies) p = MAX(p1,p2) |
| FIXED
DECIMAL (p1,q1) |
FIXED
BINARY (p2,0) |
FIXED
DECIMAL (p,q) |
p = 1
+MAX(p1- q1,v) +q q = q1 |
p = 1
+p2+v q = q1 |
p = N
q = N-p1+q1 |
FLOAT BINARY (p)
(unless special case A applies) p = MAX(CEIL (p1*3.32 ),p2) |
| FIXED
BINARY (p1,0) |
FIXED
DECIMAL (p2,q2) |
FIXED
DECIMAL (p,q) |
p = 1
+MAX(p2- q2,w) +q q = q2 |
p = 1
+p2+w q = q1 |
p = N
q = N-w-q2 |
FLOAT BINARY (p)
(unless special case B applies) p = MAX(CEIL (p1*3.32 ),p2) |
| M is the maximum precision for FIXED BINARY.
N is the maximum precision for FIXED DECIMAL. r = 1 + CEIL(p1*3.32) s = CEIL(ABS(q1*3.32)) * SIGN(q1) |
t = 1 + CEIL(p2*3.32)
u = CEIL(ABS(q2*3.32)) * SIGN(q2) v = CEIL(p2/3.32) w = CEIL(p1/3.32) |
|||||
| Notes:
The scaling factor must be in the range 0 through +127. In addition and subtraction operations, the absolute value of the difference in the scale factors must not be greater than M for FIXED BIN operations and N for FIXED DEC operations. |
||||||
| 1st Operand
(p1,q1) |
2nd Operand
(p2,q2) |
Attributes of
the Result for Addition, Subtraction, Multiplication, or Division |
Addition
or Subtraction Precision |
Multiplication
Precision |
Division
Precision |
Attributes
of the Result for Exponentiation |
|---|---|---|---|---|---|---|
| FIXED
DECIMAL (p1,q1) |
FIXED
DECIMAL (p2,q2) |
FIXED
DECIMAL (p,q) |
p = 1
+MAX(p1-q1, p2-q2) +q q = MAX(q1,q2) |
p = 1
+p1+p2 q = q1+q2 |
p = N
q = N-p1+q1-q2 |
FLOAT DECIMAL (p)
(unless special case A applies) p = MAX(p1,p2) |
| FIXED
BINARY (p1,q1) |
FIXED
BINARY (p2,q2) |
FIXED
BINARY (p,q) |
p = 1
+MAX(p1-q1, p2-q2) +q q = MAX(q1,q2) |
p = 1
+p1+p2 q = q1+q2 |
p = M
q = M-p1 +q1-q2 |
FLOAT BINARY (p)
(unless special case B applies) p = MAX(p1,p2) |
| FIXED
DECIMAL (p1,q1) |
FIXED
BINARY (p2,q2) |
FIXED
BINARY (p,q) |
p = 1
+MAX(r-s, p2-q2)+q q = MAX(s,q2) |
p = 1+r
+p2 q = s+q2 |
p = M
q = M-r +s-q2 |
FLOAT BINARY (p)
(unless special case A applies) p =MAX( CEIL((p1*3.32 ),p2) |
| FIXED
BINARY (p1,q1) |
FIXED
DECIMAL (p2,q2) |
FIXED
BINARY (p,q) |
p = 1
+MAX(p1- q1,t-u) +q q = MAX(s,q1,u) |
p = 1
+p1+t q = q1+u |
p = M
q = M-p1 +q1-u |
FLOAT BINARY (p)
(unless special case B applies) p = MAX(p1, CEIL(p2*3.32)) |
| M is the maximum precision for FIXED BINARY.
N is the maximum precision for FIXED DECIMAL. r = 1 + CEIL(p1*3.32) s = CEIL(ABS(q1*3.32)) * SIGN(q1) |
t = 1 + CEIL(p2*3.32)
u = CEIL(ABS(q2*3.32)) * SIGN(q2) v = CEIL(p2/3.32) w = CEIL(p1/3.32) |
|||||
| Notes:
The scaling factor must be in the range 0 through +127. In addition and subtraction operations, the absolute value of the difference in the scale factors must not be greater than M for FIXED BIN operations and N for FIXED DEC operations.
|
||||||
Consider the following expression:
A * B + C
The operation A * B is performed first, to give
an intermediate result. Then the value of the expression is obtained
by performing the operation (intermediate result) + C.
PL/I gives the intermediate result attributes the same way it gives attributes to any variable. The attributes of the result are derived from the attributes of the two operands (or the single operand in the case of a prefix operation) and the operator involved. The way the attributes of the result are derived is further explained under Targets.
The ADD, SUBTRACT, MULTIPLY, and DIVIDE built-in functions allow you to override the implementation precision rules for addition, subtraction, multiplication, and division operations.