TAL Reference Manual

Expressions
TAL Reference Manual526371-001
4-8
Signed Arithmetic Operators
A positive fpoint specifies the number of decimal places to the right of the decimal
point:
FIXED(3) x := 0.642F; !Stored as 642
A negative fpoint specifies a number of integer places to the left of the decimal point.
To store a FIXED value, a negative
fpoint truncates the value leftward from the decimal
point by the specified number of digits. When you access the FIXED value, zeros
replace the truncated digits:
FIXED(-3) y := 642945F; !Stored as 642; accessed
! as 642000
When FIXED operands in an arithmetic expression have different fpoints, the system
makes adjustments depending on the operator.
In addition or subtraction, the system adjusts the smaller fpoint to match the larger
fpoint. The result inherits the larger fpoint. For example, the system adjusts the
smaller
fpoint in 3.005F + 6.01F to 6.010F, and the result is 9.015F.
In multiplication, the fpoint of the result is the sum of the fpoints of the two
operands. For example, 3.091F * 2.56F results in the FIXED(5) value 7.91296F.
In division, the fpoint of the result is the fpoint of the dividend minus the fpoint of
the divisor. (Some precision is lost.) For example, 4.05F / 2.10F results in the
FIXED(0) value 1.
To retain precision when you divide operands that have nonzero
fpoints, use the
$SCALE standard function to scale up the
fpoint of the dividend by a factor equal to the
fpoint of the divisor; for example:
FIXED(3) result, a, b; ! fpoint of 3
result := $SCALE(a,3) / b; !Scale A to FIXED(6); result
! is a FIXED(3) value
The following example shows how the system makes automatic adjustments when
operands in an expression have different
fpoints: