Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Environment and Utilities /
Chapter 8 - QuickDraw GX Mathematics / About QuickDraw GX Mathematics


Number Formats

QuickDraw GX accepts standard integer and floating-point number formats, and defines several fixed-point number formats.

Integer Formats

Some Quickdraw GX functions and data structures may make use of the standard C language integer formats short, unsigned short, long, and unsigned long. The short number format is a 16-bit signed or unsigned integer; the long number format is a 32-bit signed or unsigned integer. Numbers in these formats have the following ranges of values:
FormatRange
short-32, 768 to 32,767
unsigned short0 to 65,535
long-2,147,483,648 to 2,147,483,647
unsigned long0 to 4,294,967,295

Floating-Point Formats

QuickDraw GX supports conversion to and from the C language single precision floating-point format float; double precision floating-point format double; and extra precision floating-point format extended. QuickDraw GX macros that convert between floating-point numbers and Fixed or fract numbers can handle all three floating-point formats.

Fixed-Point Formats

QuickDraw GX defines 16-bit, 32-bit, and 64-bit fixed-point number formats. Fixed-point number formats are integers that are interpreted as real numbers. The conversion between integer number format and a fixed-point number format is described by bias. A bias is a number (commonly expressed as a power of 2) by
which an integer is divided in order to obtain the real number it represents. For
example, the bias for the Fixed number format is 16 bits, or 216. In this case, the
integer must be divided by 216 to obtain the real number represented. Therefore, Fixed 0x10000 = 65,536/216, or 1.0.

There are one 16-bit, two 32-bit, and one 64-bit number formats:

All of the fixed-point number formats except for gxColorValue are two's complement signed integers.

The wide data type is defined as a structure that contains an unsigned long integer as its low-order half and a signed long integer as its high-order half. You can convert a long into a wide in either of two ways:

The WideShift function is described on page 8-51. The wide structure is described on page 8-35.

Working With Bias in Fixed-Point Operations

Fixed numbers have a bias of 16; fract numbers have a bias of 30; and long and wide numbers have a bias of 0. Unless stated otherwise, all biases will be powers of 2. For brevity, we use the convention of describing a bias by the exponent of 2; for example, we say "a bias of 16" instead of "a bias of 16 bits."Operations that are designed to work on a specific number format (such as FixedMultiply or FractDivide or WideMultiply) apply a bias to the result of their operations that reflects the number format they expect. If you understand how the bias is applied, you can use (and even mix) any of several different fixed-point number formats in these functions, and know what bias to use when interpreting the result:

Remember also that using the standard C operators + and - to add or subtract fixed-point numbers is meaningful only if the numbers have the same bias. Thus, if you wish to add together a long integer and a Fixed, for example, you must first convert one format to the other, or convert both to a common format.

The functions referred to in this section are described in the section "Fixed-Point Operations" beginning on page 8-42, and "Operations on wide Numbers" beginning on page 8-49.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996