BurgerLib
Static Public Member Functions
Burger::FracMath Class Reference

Functions to handle Frac point integer math. More...

#include <fxfixed.h>

List of all members.

Static Public Member Functions

static Frac32 BURGER_API MultiplySaturate (Frac32 fInputMulA, Frac32 fInputMulB)
 Multiply two 2.30 fixed point numbers with saturation.
static Frac32 BURGER_API DivideSaturate (Frac32 fInputNumerator, Frac32 fInputDenominator)
 Divide a 2.30 fixed point number with saturation.
static Frac32 BURGER_API CosFromFixed (Fixed32 fRadians)
 Calculate a cosine from a Fixed32 radian value.
static Frac32 BURGER_API SinFromFixed (Fixed32 fRadians)
 Calculate a sine from a Fixed32 radian value.

Detailed Description

Functions to handle Frac point integer math.

Not all modern computers have floating point support in hardware, so to get hiogh precision fractional values, a 2.30 integer format is used.

How it works is simple. The upper 2 bits are treated as a 2 bit whole integer while the lower 30 bits represent the numerator of the fraction x/1073741824. Using this method, 1.5f is represented at 0x60000000.

These routines will make it easy to perform conversion of numbers to this numeric type and to handle the most common mathematical operations with 1/1073741824th precision.

Many of these functions are inline or written in assembly language for speed.

See also:
Fixed32, Frac32 or Int32

Member Function Documentation

Calculate a cosine from a Fixed32 radian value.

Given a radian value of Burger::PiFixed32 to - Burger::PiFixed32 return the cosine value as a Frac32 from -1 to 1

Parameters:
fRadiansA Fixed32 value in radians
Returns:
Cosine in Frac32 precision.
Frac32 BURGER_API Burger::FracMath::DivideSaturate ( Frac32  fInputNumerator,
Frac32  fInputDenominator 
) [static]

Divide a 2.30 fixed point number with saturation.

Perform a signed division of two 32-bit fixed point numbers and return the Frac point result. If the answer exceeds the range allowable for a Frac32 value, it will be saturated to the minimum and maximum bounds. Division by zero will return positive or negative maximums.

Parameters:
fInputNumeratorValue to divide
fInputDenominatorValue to divide with
Returns:
Result of fInputNumerator / fInputDenominator with saturation.
See also:
Burger::FixedMath::Divide(Fixed32,Fixed32)
Frac32 BURGER_API Burger::FracMath::MultiplySaturate ( Frac32  fInputMulA,
Frac32  fInputMulB 
) [static]

Multiply two 2.30 fixed point numbers with saturation.

Perform a signed multiplication of two 32-bit frac point numbers and return the frac point result. If the value exceeds the range allowable for a Frac32 value, it will be saturated to the minimum and maximum bounds.

Parameters:
fInputMulAFirst signed value to multiply
fInputMulBSecond signed value to multiply
Returns:
Result of fInputMulA * fInputMulB with saturation.

Calculate a sine from a Fixed32 radian value.

Given a radian value of Burger::PiFixed32 to - Burger::PiFixed32 return the sine value as a Frac32 from -1 to 1

Parameters:
fRadiansA Fixed32 value in radians
Returns:
Sine in Frac32 precision.