Static Public Member Functions

Burger::IntMath Class Reference

Helper routines for integer math. More...

#include <fxfixed.h>

List of all members.

Static Public Member Functions

static Word BURGER_INLINE GetLoWord (Word32 uInput)
 Return the low 16 bits of a 32 bit value..
static Word BURGER_INLINE GetHiWord (Word32 uInput)
 Return the upper 16 bits of a 32 bit value..
static Word32 BURGER_API HexIt (Word uInput)
 Convert a 16 bit value into a 4 char string in an integer.
static void BURGER_API HexIt (char *pOutput, Word uInput)
 Convert a 16 bit value into a 4 char string.
static Word32 BURGER_INLINE UMultiply (Word uInputA, Word uInputB)
 Multiply two unsigned Word32 values.
static Int32 BURGER_INLINE Multiply (Int32 iInputA, Int32 iInputB)
 Multiply two signed Int32 values.
static int BURGER_INLINE FromFixedFloor (Fixed32 fInput)
 Convert a fixed point value to an integer using round down.
static int BURGER_INLINE FromFixed (Fixed32 fInput)
 Convert a fixed point value to an integer using round to zero.
static int BURGER_INLINE FromFixedCeil (Fixed32 fInput)
 Convert a fixed point value to an integer using round up.
static int BURGER_INLINE FromFixedNearest (Fixed32 fInput)
 Convert a fixed point value to an integer using round to nearest.
static Int32 BURGER_INLINE Abs (Int32 iInput)
 Get the absolute value of an integer..
static Word BURGER_API SqrtFromInt (Word32 uInput)
 Get the square root of an integer.
static Word BURGER_API SqrtFromFixed (Fixed32 fInput)
 Get the square root of a Fixed32.
static Int32 BURGER_API Mul32GetUpper32 (Int32 iInputA, Int32 iInputB)
 Get the upper 32 bits from a 32x32 bit multiplication.
static Int32 BURGER_API Mul32x32To64Div32 (Int32 iInputMulA, Int32 iInputMulB, Int32 iInputDiv)
 Perform a (32x32)/32 operation with 64 bit accuracy.
static Int32 BURGER_API FromFloatFloor (float fInput)
 Convert a single float to an integer using floor().
static Int32 BURGER_API FromFloat (float fInput)
 Convert a single float to an integer using round to zero.
static Int32 BURGER_API FromFloatCeil (float fInput)
 Convert a single float to an integer using ceil().
static Int32 BURGER_API FromFloatNearest (float fInput)
 Convert a single float to an integer using round to nearest.
static void BURGER_INLINE FromFloatFloor (Int32 *pOutput, float fInput)
 Convert a single float to an integer using floor().
static void BURGER_INLINE FromFloat (Int32 *pOutput, float fInput)
 Convert a single float to an integer using round to zero.
static void BURGER_INLINE FromFloatCeil (Int32 *pOutput, float fInput)
 Convert a single float to an integer using ceil().
static void BURGER_INLINE FromFloatNearest (Int32 *pOutput, float fInput)
 Convert a single float to an integer using round to nearest.

Detailed Description

Helper routines for integer math.

Some compilers don't have common math functions, also some function require intermediate values of a higher precision that can be provided by the compiler.

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


Member Function Documentation

Burger::IntMath::Abs ( Int32  iInput  )  [inline, static]

Get the absolute value of an integer..

Without branching, calculate the absolute value of an integer.

Parameters:
iInput Value to get the absolute value of.
Returns:
The absolute value of iInput.
See also:
Burger::FixedMath::Abs(Fixed32)
Burger::IntMath::FromFixed ( Fixed32  fInput  )  [inline, static]

Convert a fixed point value to an integer using round to zero.

Convert a Fixed32 into a int using round to zero.

Parameters:
fInput Value to convert to an integer.
Returns:
The input converted to an integer using the truth table below.
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(1.1f));      //1
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(1.95f));     //1
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(-1.1f));     //-1
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(-1.95f));    //-1
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(0.1f));      //0
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(0.95f));     //0
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(-0.1f));     //0
    floorint = Burger::IntMath::FromFixed(FLOATTOFIXED(-0.95f));    //0
Burger::IntMath::FromFixedCeil ( Fixed32  fInput  )  [inline, static]

Convert a fixed point value to an integer using round up.

Convert a Fixed32 into a int using the same formula as ceil().

Parameters:
fInput Value to convert to an integer.
Returns:
The input converted to an integer using the truth table below.
Burger::IntMath::FromFixedFloor ( Fixed32  fInput  )  [inline, static]

Convert a fixed point value to an integer using round down.

Convert a Fixed32 into a int using the same formula as floor().

Parameters:
fInput Value to convert to an integer.
Returns:
The input converted to an integer using the truth table below.
Burger::IntMath::FromFixedNearest ( Fixed32  fInput  )  [inline, static]

Convert a fixed point value to an integer using round to nearest.

Convert a Fixed32 into a int using round to nearest.

Parameters:
fInput Value to convert to an integer.
Returns:
The input converted to an integer using the truth table below.
Note:
This can be used to replace FixRound() from MacOS.
Int32 BURGER_API Burger::IntMath::FromFloat ( float  fInput  )  [static]

Convert a single float to an integer using round to zero.

Convert a single precision floating point number to an integer using the round to zero fractional truncation

Parameters:
fInput A valid single precision floating point number.
Returns:
Signed integer equivalent value after applying round to zero on the floating point number.
void Burger::IntMath::FromFloat ( Int32 pOutput,
float  fInput 
) [inline, static]

Convert a single float to an integer using round to zero.

Convert a single precision floating point number to an integer using the round to zero fractional truncation and store it to memory

Parameters:
pOutput A valid pointer to a 32-bit integer to receive the result.
fInput A valid single precision floating point number.
Int32 BURGER_API Burger::IntMath::FromFloatCeil ( float  fInput  )  [static]

Convert a single float to an integer using ceil().

Convert a single precision floating point number to an integer using the ceil() form of fractional truncation

Parameters:
fInput A valid single precision floating point number.
Returns:
Signed integer equivalent value after applying ceil() on the floating point number.
void Burger::IntMath::FromFloatCeil ( Int32 pOutput,
float  fInput 
) [inline, static]

Convert a single float to an integer using ceil().

Convert a single precision floating point number to an integer using the ceil() form of fractional truncation and store it to memory

Parameters:
pOutput A valid pointer to a 32-bit integer to receive the result.
fInput A valid single precision floating point number.
Int32 BURGER_API Burger::IntMath::FromFloatFloor ( float  fInput  )  [static]

Convert a single float to an integer using floor().

Convert a single precision floating point number to an integer using the floor() form of fractional truncation

Parameters:
fInput A valid single precision floating point number.
Returns:
Signed integer equivalent value after applying floor() on the floating point number.
void Burger::IntMath::FromFloatFloor ( Int32 pOutput,
float  fInput 
) [inline, static]

Convert a single float to an integer using floor().

Convert a single precision floating point number to an integer using the floor() form of fractional truncation and store it to memory

Parameters:
pOutput A valid pointer to a 32-bit integer to receive the result.
fInput A valid single precision floating point number.
void Burger::IntMath::FromFloatNearest ( Int32 pOutput,
float  fInput 
) [inline, static]

Convert a single float to an integer using round to nearest.

Convert a single precision floating point number to an integer using the round to nearest fractional truncation and store it to memory

Parameters:
pOutput A valid pointer to a 32-bit integer to receive the result.
fInput A valid single precision floating point number.
Int32 BURGER_API Burger::IntMath::FromFloatNearest ( float  fInput  )  [static]

Convert a single float to an integer using round to nearest.

Convert a single precision floating point number to an integer using the round to nearest fractional truncation

Parameters:
fInput A valid single precision floating point number.
Returns:
Signed integer equivalent value after applying round to nearest on the floating point number.
Burger::IntMath::GetHiWord ( Word32  uInput  )  [inline, static]

Return the upper 16 bits of a 32 bit value..

This is a direct replacement of the MacOS macro HiWord(). Take the 32 bit input and shift it to the right 16 bits, effectively uInput>>16.

Parameters:
uInput 32-bit integer value.
Returns:
Value shifted to the right 16 bits
Burger::IntMath::GetLoWord ( Word32  uInput  )  [inline, static]

Return the low 16 bits of a 32 bit value..

This is a direct replacement of the MacOS macro LoWord(). Take the 32 bit input and mask it with 0xFFFF, then return the result.

Parameters:
uInput 32-bit integer value.
Returns:
Value masked with 0xFFFF.
void BURGER_API Burger::IntMath::HexIt ( char *  pOutput,
Word  uInput 
) [static]

Convert a 16 bit value into a 4 char string.

Convert a 16-bit value into a 4 character ASCII string. This function will NOT zero terminate the string and it's expecting a buffer of at least 4 bytes in length.

Input : 0x1234 Output : "1234"

Parameters:
uInput Value to convert
pOutput Pointer to a four character buffer.
Note:
The upper 16 bits of the input are ignored.
Word32 BURGER_API Burger::IntMath::HexIt ( Word  uInput  )  [static]

Convert a 16 bit value into a 4 char string in an integer.

This is a compatibility function of HexIt() from MacOS.

Convert a 16-bit value into a Word32 that contains the ASCII value of the short... The result is BIG Endian so that it can be directly stored into an ASCII buffer without an Endian swap

Input : 0x1234 Output : '1','2','3','4' -> 0x31323334 (Big Endian)

Parameters:
uInput Value to convert
Returns:
Big Endian "String" in a Word32.
Note:
The upper 16 bits of the input are ignored.
Int32 Burger::IntMath::Mul32GetUpper32 ( Int32  iInputA,
Int32  iInputB 
) [static]

Get the upper 32 bits from a 32x32 bit multiplication.

Multiply two 32-bit values and create a 64 bit result. Discard the lower 32 bits and return only the upper 32 bits. This is a signed multiplication.

Parameters:
iInputA First value to multiply.
iInputB Second value to multiply.
Returns:
The upper 32 bits of the 64 bit result.
Note:
On PowerPC, this becomes the mulhw instruction and Intel it's the imul edx instruction.
Int32 Burger::IntMath::Mul32x32To64Div32 ( Int32  iInputMulA,
Int32  iInputMulB,
Int32  iInputDiv 
) [static]

Perform a (32x32)/32 operation with 64 bit accuracy.

Multiply two 32-bit values and create a 64 bit result. Then divide this value by a 32 bit number. This will allow several ratio functions to operate with high accuracy. Result = ((int64)32*(int64)32)/32).

Parameters:
iInputMulA First value to multiply.
iInputMulB Second value to multiply.
iInputDiv Value to divide the 64 bit value by
Returns:
Output from the formula (A*B)/C
Note:
On Intel, this becomes imul edx followed by idiv ebx
Burger::IntMath::Multiply ( Int32  iInputA,
Int32  iInputB 
) [inline, static]

Multiply two signed Int32 values.

This function is considered obsolete and remains only for backwards compatibilty.

Parameters:
iInputA 32-bit signed integer value.
iInputB 32-bit signed integer value.
Returns:
The result of the multiplication of the two inputs.
Note:
No overflow checking is performed.
Word BURGER_API Burger::IntMath::SqrtFromFixed ( Fixed32  fInput  )  [static]

Get the square root of a Fixed32.

Return the square root of a Fixed32 and return the integer result. The maximum value is 255.998 (256) for the square root of 0x7FFFFFFF. This routine is 100% accurate.

Negative numbers will return zero for the result.

Parameters:
fInput Value to return the square root of.
Returns:
Return the square root as an integer.
Note:
This will perform a round to nearest for the fraction so if the calculated square root is 1.6, it will return 2.
Word BURGER_API Burger::IntMath::SqrtFromInt ( Word32  uInput  )  [static]

Get the square root of an integer.

Return the square root of an integer. The maximum value is 46341 for the square root of 0x7FFFFFFF. This routine is 100% accurate.

Parameters:
uInput Value to return the square root of.
Returns:
Return the square root as an integer.
Note:
This will perform a round to nearest for the fraction so if the calculated square root is 1.6, it will return 2.
Burger::IntMath::UMultiply ( Word  uInputA,
Word  uInputB 
) [inline, static]

Multiply two unsigned Word32 values.

This is a direct replacement of the MacOS function Multiply(). This function is considered obsolete and remains only for backwards compatibilty.

Parameters:
uInputA 32-bit unsigned integer value.
uInputB 32-bit unsigned integer value.
Returns:
The result of the multiplication of the two inputs.
Note:
No overflow checking is performed.