Helper routines for integer math. More...
#include <fxfixed.h>
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. | |
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.
| Burger::IntMath::Abs | ( | Int32 | iInput | ) | [inline, static] |
Get the absolute value of an integer..
Without branching, calculate the absolute value of an integer.
| iInput | Value to get the absolute value of. |
| 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.
| fInput | Value to convert to an integer. |
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().
| fInput | Value to convert to an integer. |
floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(1.1f)); //2 floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(1.95f)); //2 floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(-1.1f)); //-1 floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(-1.95f)); //-1 floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(0.1f)); //1 floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(0.95f)); //1 floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(-0.1f)); //0 floorint = Burger::IntMath::FromFixedCeil(FLOATTOFIXED(-0.95f)); //0
| 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().
| fInput | Value to convert to an integer. |
floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(1.1f)); //1 floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(1.95f)); //1 floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(-1.1f)); //-2 floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(-1.95f)); //-2 floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(0.1f)); //0 floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(0.95f)); //0 floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(-0.1f)); //-1 floorint = Burger::IntMath::FromFixedFloor(FLOATTOFIXED(-0.95f)); //-1
| 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.
| fInput | Value to convert to an integer. |
floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(1.1f)); //1 floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(1.95f)); //2 floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(-1.1f)); //-1 floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(-1.95f)); //-2 floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(0.1f)); //0 floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(0.95f)); //1 floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(-0.1f)); //0 floorint = Burger::IntMath::FromFixedNearest(FLOATTOFIXED(-0.95f)); //-1
| 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
| fInput | A valid single precision 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
| 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
| fInput | A valid single precision 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
| 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
| fInput | A valid single precision 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
| 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
| 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
| fInput | A valid single precision 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.
| uInput | 32-bit integer value. |
| 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.
| uInput | 32-bit integer value. |
| 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"
| uInput | Value to convert | |
| pOutput | Pointer to a four character buffer. |
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)
| uInput | Value to convert |
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.
| iInputA | First value to multiply. | |
| iInputB | Second value to multiply. |
| 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).
| iInputMulA | First value to multiply. | |
| iInputMulB | Second value to multiply. | |
| iInputDiv | Value to divide the 64 bit value by |
Multiply two signed Int32 values.
This function is considered obsolete and remains only for backwards compatibilty.
| iInputA | 32-bit signed integer value. | |
| iInputB | 32-bit signed integer value. |
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.
| fInput | Value to return the square root of. |
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.
| uInput | Value to return the square root of. |
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.
| uInputA | 32-bit unsigned integer value. | |
| uInputB | 32-bit unsigned integer value. |
1.7.1