pTAL Reference Manual (H06.08+)

Expressions
HP pTAL Reference Manual523746-006
5-7
Scaling of FIXED Operands
The compiler treats a STRING or UNSIGNED(1-16) operand as an INT operand. If
bit <0> contains 0, the operand is positive; if bit <0> contains 1, the operand is
negative. For more information, see Data Types of Expressions on page 5-2.
The compiler treats an UNSIGNED(17-31) operand as a positive INT(32) operand.
Signed arithmetic operators affect the hardware indicators as described in Section 13,
Hardware Indicators.
Topics:
Scaling of FIXED Operands on page 5-7
Using FIXED(*) Variables on page 5-8
Scaling of FIXED Operands
When you declare a FIXED variable, you can specify an implied fixed-point (fpoint )
setting (see Specifying Data Types on page 3-3).
When FIXED operands in an arithmetic expression have different fixed-points, the
system scales them, depending on the operation:
To retain precision when you divide operands that have nonzero fixed-points, use the
routine $SCALE on page 15-82.
INT UNSIGNED(1-16) INT word + unsign12
INT(32) UNSIGNED(17-31) INT(32) double + unsign20
UNSIGNED(1-16) UNSIGNED(1-16) INT unsign6 + unsign9
UNSIGNED(17-31) UNSIGNED(17-31) INT(32) unsign26 + unsign31
Operation Scaling
Addition or
subtraction
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.
Multiplication 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.
Division 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.
Table 5-5. Signed Arithmetic Operand and Result Types (page 2 of 2)
Operand Type Operand Type Result Type Example