Documentation  |   Table of Contents   |  < Previous   |  Next >   |  Index

19    Fixed Math Reference

User Interface

Exploring Palm OS®

This chapter describes the fixed-point computations declared in FixedMath.h. It covers:

Fixed Math Structures and Types
Fixed Math Constants
Fixed Math Functions and Macros

Fixed Math Structures and Types ^TOP^

Fixed Typedef ^TOP^

Purpose

A signed fixed-point value.

Declared In

FixedMath.h

Prototype

typedef int32_t Fixed

Fixed32 Typedef ^TOP^

Purpose

An unsigned fixed-point 32-bit value.

Declared In

FixedMath.h

Prototype

typedef uint32_t Fixed32

Fixed32Intermediate Typedef ^TOP^

Purpose

Type used to store intermediate values when working with fixed-point numbers.

Declared In

FixedMath.h

Prototype

typedef unsigned long long Fixed32Intermediate

FixedIntermediate Typedef ^TOP^

Purpose

Type used to store intermediate values when working with fixed-point numbers.

Declared In

FixedMath.h

Prototype

typedef Fixed32Intermediate FixedIntermediate

Fixed Math Constants ^TOP^

Fixed-Point Constants ^TOP^

Purpose

Constants declared in FixedMath.h.

Declared In

FixedMath.h

Constants

#define kFixed32Bias (16)
Use 16 bits for the integer portion and 16 bits for the fractional portion.
#define kFixed32FractionMask (0x0000FFFF)
A mask used to access the fractional portion of a Fixed32 value.
#define kFixedBias kFixed32Bias
Use 16 bits for the integer portion and 16 bits for the fractional portion.
#define kFixedFractionMask kFixed32FractionMask
A mask used to access the fractional portion of a Fixed value.
#define kFixedOne 0x00010000
The integer value 1.
#define kFixedOneAndOneHalf 0x00018000
The value 1.5.
#define kFixedOneHalf 0x00008000
The value 0.5.
#define kFixedTwo 0x00020000
The value 2.
#define kFixedTwoThirds 0x0000AAAB
The value 2/3 (0.666666667).

Fixed Math Functions and Macros ^TOP^

DivIntByFixedResultInt Macro ^TOP^

Purpose

Divides one value by another and returns an integer.

Declared In

FixedMath.h

Prototype

#define DivIntByFixedResultInt (
   lhs,
    rhs
)

Parameters

lhs
An integer value.
rhs
A fixed-point value.

Returns

An integer value representing lhs divided by rhs.

Fixed32Div Macro ^TOP^

Purpose

Divides one Fixed32 value by another.

Declared In

FixedMath.h

Prototype

#define Fixed32Div (
   lhs,
    rhs
)

Parameters

lhs
The dividend.
rhs
The divisor.

Returns

The quotient produced when lhs is divided by rhs.

Fixed32Fraction Macro ^TOP^

Purpose

Accesses the fractional part of a 32-bit fixed point value.

Declared In

FixedMath.h

Prototype

#define Fixed32Fraction (
   x
)

Parameters

x
A 32-bit fixed point value.

Returns

A 32-bit fixed point value with only the fractional portion of the value as nonzero.

Fixed32FromInteger Macro ^TOP^

Purpose

Converts an integer into a Fixed32 value.

Declared In

FixedMath.h

Prototype

#define Fixed32FromInteger (
   n
)

Parameters

n
A 16-bit integer.

Returns

A Fixed32 with the integer portion assigned to n and the fractional portion of 0.

Fixed32Mul Macro ^TOP^

Purpose

Multiplies two fixed-point values.

Declared In

FixedMath.h

Prototype

#define Fixed32Mul (
   lhs,
    rhs
)

Parameters

lhs
The left operand.
rhs
The right operand.

Returns

The product of lhs and rhs as a Fixed32 value.

Fixed32ToInteger Macro ^TOP^

Purpose

Converts a Fixed32 value to an integer type.

Declared In

FixedMath.h

Prototype

#define Fixed32ToInteger (
   n
)

Parameters

n
A Fixed32 value.

Returns

A uint32_t value representing only the integer portion of n. The fractional portion is discarded.

FixedAdd Macro ^TOP^

Purpose

Adds two Fixed values.

Declared In

FixedMath.h

Prototype

#define FixedAdd (
   lhs,
    rhs
)

Parameters

lhs
The left operand.
rhs
The right operand.

Returns

The sum of lhs and rhs.

FixedDiv Macro ^TOP^

Purpose

Divides one value by another.

Declared In

FixedMath.h

Prototype

#define FixedDiv (
   lhs,
    rhs
)

Parameters

lhs
The divisor.
rhs
The dividend.

Returns

The quotient produced when lhs is divided by rhs. If both parameters are Fixed, the result is Fixed. If the values are integers, the result is an integer.

FixedFraction Macro ^TOP^

Purpose

Accesses the fractional part of a fixed-point value.

Declared In

FixedMath.h

Prototype

#define FixedFraction (
   x
)

Parameters

x
A Fixed value.

Returns

A fixed point value with only the fractional portion of the value as nonzero.

FixedFromInteger Macro ^TOP^

Purpose

Converts an integer into a Fixed32 value.

Declared In

FixedMath.h

Prototype

#define FixedFromInteger (
   x
)

Parameters

x
A 16-bit integer.

Returns

A Fixed number with the integer portion assigned to x and the fractional portion of 0.

FixedMul Macro ^TOP^

Purpose

Multiplies two values.

Declared In

FixedMath.h

Prototype

#define FixedMul (
   lhs,
    rhs
)

Parameters

lhs
The left operand.
rhs
The right operand.

Returns

The product of lhs and rhs. The product is a Fixed value, if both parameters are Fixed, otherwise, it is an integer value.

FixedMulByFixed Macro ^TOP^

Purpose

Multiplies two values and returns the result as a Fixed value.

Declared In

FixedMath.h

Prototype

#define FixedMulByFixed (
   lhs,
    rhs
)

Parameters

lhs
The left operand.
rhs
The right operand.

Returns

The product of lhs and rhs as a Fixed value.

FixedMulByInt16 Macro ^TOP^

Purpose

Multiplies two values and returns the result as a 16-bit integer.

Declared In

FixedMath.h

Prototype

#define FixedMulByInt16 (
   lhs,
    rhs
)

Parameters

lhs
The left operand.
rhs
The right operand.

Returns

The product of lhs and rhs as a uint16_t value.

FixedMulByInt32 Macro ^TOP^

Purpose

Multiplies two values and returns the result as a 32-bit integer.

Declared In

FixedMath.h

Prototype

#define FixedMulByInt32 (
   lhs,
    rhs
)

Parameters

lhs
The left operand.
rhs
The right operand.

Returns

The product of lhs and rhs as a uint32_t value.

FixedPower2Div Macro ^TOP^

Purpose

Divides a value by a power of 2.

Declared In

FixedMath.h

Prototype

#define FixedPower2Div (
   x,
    power
)

Parameters

x
The dividend.
power
The exponent value for 2.

Returns

The value of x / 2power.

FixedPower2Mul Macro ^TOP^

Purpose

Multiplies a value by a power of 2.

Declared In

FixedMath.h

Prototype

#define FixedPower2Mul (
   x,
    power
)

Parameters

x
The value to multiply.
power
The exponent value for 2.

Returns

The value of x * 2power.

FixedSub Macro ^TOP^

Purpose

Subtracts one Fixed value from another.

Declared In

FixedMath.h

Prototype

#define FixedSub (
   lhs,
    rhs
)

Parameters

lhs
The left operand.
rhs
The right operand.

Returns

The difference when rhs is subtracted from lhs.

FixedToInteger Macro ^TOP^

Purpose

Converts a Fixed value to an integer.

Declared In

FixedMath.h

Prototype

#define FixedToInteger (
   x
)

Parameters

x
A Fixed value.

Returns

A uint32_t value representing only the integer portion of x. The fractional portion is discarded.