Specifications

Apple II Technical Notes
Apple IIGS
2 of 2 #79: Integer Math Data Types
-32768
16384 8192 4 2 1
1
2
1
4
1
8
1
16384
1
32768
1
65536
low-order word
high-order word
012
15 14 13
. . .
. . .
31 30 29 18 17 16
Figure 1–Fixed Data Type
The format for the Frac data type is stated in the manual as being a 32-bit signed value with 30
bits of fraction. This means that the low-order 30 bits of the Frac format data value are
considered as a fraction of 2^30, which is the binary number represented by a one followed by
30 zeroes ($40000000). In other words, a Frac value is the same as a long integer value whose
binary point has been moved to the left 30 places. The high-order 2 bits of the Frac format data
value are treated as follows. The high bit has a value of -2 and the low bit has a value of 1.
Therefore the highest value that a Frac can contain is 1 and ((2^30)-1)/2^30; the least value is
equal to -2.
1
-2
1
2
31 1630 29 1718
012
15 14 13
1
4096
1
8192
1
16384
1
32768
1
65536
1
131072
. . .
. . .
high-order word
low-order word
1
1073741824
1
536870912
1
268435456
Figure 2–Frac Data Type
Note that for Longints, Fixed, and Frac values, the hex representations of the largest and
smallest data values are $7FFFFFFF and $80000000, respectively.
A property of the Fixed and Frac data types is that two Fixed or two Frac values may be
added or subtracted just as if they were 32-bit integers. To demonstrate this, imagine scaling the
numbers by a given factor to make them integers. After adding the numbers, the sum could be
scaled back down by the same factor. This follows from the distributive property of
multiplication over addition, which allows one to make the inference shown in the equations
which follow. In these equations, V1 and V2 are both either Fixed or Frac values. The value
for C being discussed, which illustrates the ability to scale Fixed and Frac values, is 2^16 for
Fixed values of V1 and V2, or 2^30 for Frac values of V1 and V2.
(C * V1) + (C * V2) C * (V1 + V2)
___________________ = _____________ = V1 + V2
C C