The FIXED_POINT statement has the form

FIXED_POINT.n variable,variable,...

where the variables belong to some integer type (INTEGER, LONG, UNSIGNED, BCD, NUMERIC, and so on). These instruct the compiler to treat these variables as containing numbers with n digits after the decimal point rather than true integers.

Thus, where a and b are declared to be FIXED_POINT.3, the calculation of a+b and a-b is not affected (but the result is of type FIXED_POINT.3, not INTEGER), but a*b is calculated as follows using integer arithmetic:

multiply a by b, allowing the result to have twice the length of either variable,

then divide the result by 1000

since the integer a is really a*1000, and similarly for b, a*b by integer arithmetic is (a*b)*1000000, which when divided by 1000 is (a*b)*1000, the integer form of what a*b should actually be.Not every computer can handle double length intermediate results in integer arithmetic in assembly language; the 68000 will produce such results by multiplication, but cannot divide them directly.

The form FIXED_POINT.n/b is also allowed, where b replaces 10 as the item to be taken to the n-th power to determine the scale factor for such integers.

[Next] [Up/Previous]