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
Fixed Typedef
Purpose
Declared In
FixedMath.h Prototype
typedef int32_t Fixed
Fixed32 Typedef
Purpose
An unsigned fixed-point 32-bit value.
Declared In
FixedMath.h Prototype
typedef uint32_t Fixed32
Fixed32Intermediate Typedef
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
Purpose
Type used to store intermediate values when working with fixed-point numbers.
Declared In
FixedMath.h Prototype
typedef Fixed32Intermediate FixedIntermediate
Fixed Math Constants
Fixed-Point Constants
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
Fixed32value. -
#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
Fixedvalue. -
#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
DivIntByFixedResultInt Macro
Purpose
Divides one value by another and returns an integer.
Declared In
FixedMath.h Prototype
#define DivIntByFixedResultInt (lhs,rhs)
Parameters
Returns
An integer value representing lhs divided by rhs.
Fixed32Div Macro
Purpose
Divides one Fixed32 value by another.
Declared In
FixedMath.h Prototype
#define Fixed32Div (lhs,rhs)
Parameters
Returns
The quotient produced when lhs is divided by rhs.
Fixed32Fraction Macro
Purpose
Accesses the fractional part of a 32-bit fixed point value.
Declared In
FixedMath.h Prototype
#define Fixed32Fraction (
x
)
Parameters
Returns
A 32-bit fixed point value with only the fractional portion of the value as nonzero.
Fixed32FromInteger Macro
Purpose
Converts an integer into a Fixed32 value.
Declared In
FixedMath.h Prototype
#define Fixed32FromInteger (
n
)
Parameters
Returns
A Fixed32 with the integer portion assigned to n and the fractional portion of 0.
Fixed32Mul Macro
Purpose
Multiplies two fixed-point values.
Declared In
FixedMath.h Prototype
#define Fixed32Mul (lhs,rhs)
Parameters
Returns
The product of lhs and rhs as a Fixed32 value.
Fixed32ToInteger Macro
Purpose
Converts a Fixed32 value to an integer type.
Declared In
FixedMath.h Prototype
#define Fixed32ToInteger (
n
)
Parameters
-
→ n - A
Fixed32value.
Returns
A uint32_t value representing only the integer portion of n. The fractional portion is discarded.
FixedAdd Macro
Purpose
Adds two Fixed values.
Declared In
FixedMath.h Prototype
#define FixedAdd (lhs,rhs)
Parameters
Returns
FixedDiv Macro
Purpose
Declared In
FixedMath.h Prototype
#define FixedDiv (lhs,rhs)
Parameters
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
Purpose
Accesses the fractional part of a fixed-point value.
Declared In
FixedMath.h Prototype
#define FixedFraction (
x
)
Parameters
-
→ x - A
Fixedvalue.
Returns
A fixed point value with only the fractional portion of the value as nonzero.
FixedFromInteger Macro
Purpose
Converts an integer into a Fixed32 value.
Declared In
FixedMath.h Prototype
#define FixedFromInteger (
x
)
Parameters
Returns
A Fixed number with the integer portion assigned to x and the fractional portion of 0.
FixedMul Macro
Purpose
Declared In
FixedMath.h Prototype
#define FixedMul (lhs,rhs)
Parameters
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
Purpose
Multiplies two values and returns the result as a Fixed value.
Declared In
FixedMath.h Prototype
#define FixedMulByFixed (lhs,rhs)
Parameters
Returns
The product of lhs and rhs as a Fixed value.
FixedMulByInt16 Macro
Purpose
Multiplies two values and returns the result as a 16-bit integer.
Declared In
FixedMath.h Prototype
#define FixedMulByInt16 (lhs,rhs)
Parameters
Returns
The product of lhs and rhs as a uint16_t value.
FixedMulByInt32 Macro
Purpose
Multiplies two values and returns the result as a 32-bit integer.
Declared In
FixedMath.h Prototype
#define FixedMulByInt32 (lhs,rhs)
Parameters
Returns
The product of lhs and rhs as a uint32_t value.
FixedPower2Div Macro
Purpose
Divides a value by a power of 2.
Declared In
FixedMath.h Prototype
#define FixedPower2Div (x,power)
Parameters
Returns
FixedPower2Mul Macro
Purpose
Multiplies a value by a power of 2.
Declared In
FixedMath.h Prototype
#define FixedPower2Mul (x,power)
Parameters
Returns
FixedSub Macro
Purpose
Subtracts one Fixed value from another.
Declared In
FixedMath.h Prototype
#define FixedSub (lhs,rhs)
Parameters
Returns
The difference when rhs is subtracted from lhs.
FixedToInteger Macro
Purpose
Converts a Fixed value to an integer.
Declared In
FixedMath.h Prototype
#define FixedToInteger (
x
)
Parameters
Returns
A uint32_t value representing only the integer portion of x. The fractional portion is discarded.
