Saying two things at once
bbalk 1200006543 Visits (1578)
In PL/I conversions, BINARY rules over DECIMAL, and FLOAT, over FIXED.
This means, for example, that when an expression contains a BINARY and a DECIMAL operand, then the result will be BINARY.
Hence, for the assignment in this code
dcl a fixed bin;
dcl b float dec;
b = b + a;
there will be these conversions
a will be converted to FLOAT BIN
b will be converted to FLOAT BIN
the sum will be converted to FLOAT DEC
PL/I has always had a series of built-in functions (BINARY, DECIMAL, FIXED, and FLOAT) to help control such conversions.
But if you were to change the sample assignment above to
b = b + decimal(a);
then there will be these conversions
a will be converted to FIXED DEC
that result will be converted to FLOAT DEC
the sum will be simply assigned to FLOAT DEC
So one conversion has been eliminated, but there are still two conversions when one should suffice
The problem is that these functions allow you to specify only one attribute at a time when you would like to be able specify two
Enterprise PL/I 3.8 introduced 4 new built-in functions so you can do this:
FLOATDEC, FLOATBIN, FIXEDDEC, and FIXEDBIN
Now you can rewrite our assignment to
b = b + floatdec(a);
and not only will this code perform faster, it will be easier for someone to understand and maintain in the future.