pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Topics:
Scaling of FIXED Operands (page 74)
Using FIXED(*) Variables (page 74)
Scaling of FIXED Operands
When you declare a FIXED variable, you can specify an implied fixed-point (fpoint ) setting (see
Specifying Data Types (page 47)).
When FIXED operands in an arithmetic expression have different fixed-points, the system “scales
them, depending on the operation:
ScalingOperation
The system adjusts the smaller fixed-point to match the larger fixed-point. The result
inherits the larger fixed-point. For example, the system adjusts the smaller fixed-point
in 3.005F + 6.01F to 6.010F, and the result is 9.015F.
Addition or subtraction
The fixed-point of the result is the sum of the fixed-points of the two operands. For
example, 3.091F * 2.56F results in the FIXED(5) value 7.91296F.
Multiplication
The fixed-point of the result is the fixed-point of the dividend minus the fixed-point
of the divisor (some precision is lost). For example, 4.05F / 2.10F results in the
FIXED value 1.
Division
To retain precision when you divide operands that have nonzero fixed-points, use the routine
$SCALE (page 487).
Using FIXED(*) Variables
pTAL does not scale data items that it stores into FIXED(*) items.
The following procedure has one local variable whose data type is FIXED(*):
PROC p;
BEGIN
FIXED(*) f;
f := 1234F;
END;
The data type of a FIXED(*) variable is the same as a FIXED variable when it is used in an
expression:
FIXED(*) f1 := 123F;
FIXED(2) f2;
f2 := f1; ! f2 is assigned 123.00
pTAL does not scale data when it is stored into a FIXED(*) variable:
FIXED(2) f1 := 1.23F;
FIXED(*) f2;
FIXED f3;
f2 := f1; ! f2 is assigned 123
f3 := f1; ! f3 is assigned 1
The following example further illustrates this:
FIXED(*) f1;
FIXED(3) f2 := 1.234F;
f1 := f2; ! f1 = 1234
f2 := f1; ! f2 = 1234.000
f1 := f2; ! f1 = 1234000
f2 := f1; ! f2 = 1234000.000
f1 := f2; ! f1 = 1234000000
f2 := f1; ! f2 = 1234000000.000
74 Expressions