GEOS Programming: 1.3 Basic Data Types and Structures: Fixed Point Structures

Up: GEOS SDK TechDocs | Up | Prev: 1.2 Handles and Pointers | Next: 2 Goc and C

When you want to represent non-integral numbers (i.e., real numbers), you can use either the standard C floating-point format or the following special structures of GEOS for fixed point math. Note that fixed-point calculations are faster than the corresponding floating-point math, so if you want to optimize your code, you should use the GEOS fixed-point structures with the GEOS math routines.

Code Display 5-2 GEOS Data Structures

 /* Fixed-Point Structures
 *    The following structures are used to represent fixed-point numbers:
 *    numbers with a fractional portion and an integral portion. Notice that
 *    there are several formats of fixed-point numbers; each uses a different
 *    number of bits for the parts of the number. Choose whichever is most
 *    appropriate (for optimization). */
 	/* BBFixed
	 * One byte integer, one byte fraction */
typedef struct {
    byte		BBF_frac;		/* fractional portion */
    byte		BBF_int;		/* integral portion */
} BBFixed;
	/* BBFixedAsWord
	 * Sometimes it is convenient to refer to a BBFixed value as type word.
	 * The BBFixedAsWord type is used for this purpose. */
 typedef word		BBFixedAsWord;
	/* WBFixed
	 * One word integer, one byte fraction */
 typedef struct {
    byte		WBF_frac;		/* fractional portion */
    word		WBF_int;		/* integral portion */
} WBFixed;
	/* WWFixed
	 * One word integer, one word fraction */
 typedef struct {
    word		WWF_frac;		/* fractional portion */
    word		WWF_int;		/* integral portion */
} WWFixed;
	/* WWFixedAsDWord
	 * Sometimes it is convenient to refer to a WWFixed value as type dword.
	 * The WWFixedAsDWord type is used for this purpose. */
 typedef dword		WWFixedAsDWord;
	/* DWFixed
	 * two words (one dword) integer, one word fraction */
typedef struct {
    word		DWF_frac;		/* fractional portion */
    sdword		DWF_int;		/* integral portion */
 } DWFixed;
/* Three-byte structure
 * The WordAndAHalf structure is used when you need a 24-bit value and you want to
 * optimize and avoid using a 32-bit value. */
typedef struct {
    word		WAAH_low;		/* the low 16 bits */
    byte		WAAH_high;		/* the high 8 bits */
} WordAndAHalf;

Three special macros are also available to work with the WWFixed type. These are listed below:

Two other macros are provided for use with WWFixedAsDword structures:


Up: GEOS SDK TechDocs | Up | Prev: 1.2 Handles and Pointers | Next: 2 Goc and C