Functions to handle fixed point integer math. More...
#include <fxfixed.h>
Static Public Member Functions | |
| static Fixed32 BURGER_INLINE | FromInt (Int32 iInput) |
| Convert an Int32 into a Fixed32 value. | |
| static Fixed32 BURGER_INLINE | FromFloatFloor (float fInput) |
| Convert a single float to a Fixed32 using floor(). | |
| static Fixed32 BURGER_INLINE | FromFloat (float fInput) |
| Convert a single float to a Fixed32 using round to zero. | |
| static Fixed32 BURGER_INLINE | FromFloatCeil (float fInput) |
| Convert a single float to a Fixed32 using ceil(). | |
| static Fixed32 BURGER_INLINE | FromFloatNearest (float fInput) |
| Convert a single float to a Fixed32 using round to nearest. | |
| static void BURGER_INLINE | FromFloatFloor (Fixed32 *pOutput, float fInput) |
| Convert a single float to a Fixed32 using floor(). | |
| static void BURGER_INLINE | FromFloat (Fixed32 *pOutput, float fInput) |
| Convert a single float to a Fixed32 using round to zero. | |
| static void BURGER_INLINE | FromFloatCeil (Fixed32 *pOutput, float fInput) |
| Convert a single float to a Fixed32 using ceil(). | |
| static void BURGER_INLINE | FromFloatNearest (Fixed32 *pOutput, float fInput) |
| Convert a single float to a Fixed32 using round to nearest. | |
| static Fixed32 BURGER_API | FromIntSaturate (Int32 iInput) |
| Convert an Int32 into a Fixed32 value with saturation. | |
| static Fixed32 BURGER_INLINE | Abs (Fixed32 fInput) |
| Get the absolute value of a 16.16 fixed point value... | |
| static Fixed32 BURGER_API | SqrtFromInt (Word32 uInput) |
| Get the square root of an integer. | |
| static Fixed32 BURGER_API | SqrtFromFixed (Fixed32 fInput) |
| Get the square root of a Fixed32. | |
| static Fixed32 BURGER_INLINE | Multiply (Fixed32 fInputMulA, Fixed32 fInputMulB) |
| Multiply two 16.16 fixed point numbers. | |
| static Fixed32 BURGER_INLINE | Divide (Fixed32 fInputNumerator, Fixed32 fInputDenominator) |
| Divide two 16.16 fixed point numbers. | |
| static Fixed32 BURGER_INLINE | Reciprocal (Fixed32 fInput) |
| Return the reciprocal of a fixed point number. | |
| static Fixed32 BURGER_API | MultiplySaturate (Fixed32 fInputMulA, Fixed32 fInputMulB) |
| Multiply two 16.16 fixed point numbers with saturation. | |
| static Fixed32 BURGER_API | DivideSaturate (Fixed32 fInputNumerator, Fixed32 fInputDenominator) |
| Divide a 16.16 fixed point number with saturation. | |
| static Fixed32 BURGER_API | CrossProduct2DSign (Fixed32 fInputX1, Fixed32 fInputY1, Fixed32 fInputX2, Fixed32 fInputY2) |
| Return the sign of the result of a 2D cross product. | |
| static Fixed32 BURGER_API | ATan2 (Fixed32 fInput1, Fixed32 fInput2) |
| Get the arctangent from the slope of two signed integers. | |
Functions to handle fixed point integer math.
Not all modern computers have floating point support in hardware, so to get fractional values, a 16.16 integer format is used.
How it works is simple. The upper 16 bits are treated as a 16 bit whole integer while the lower 16 bits represent the numerator of the fraction x/65536. Using this method, 1.5f is represented at 0x18000.
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/65536th precision.
Many of these functions are inline or written in assembly language for speed.
| Burger::FixedMath::Abs | ( | Fixed32 | fInput | ) | [inline, static] |
Get the absolute value of a 16.16 fixed point value...
Without branching, calculate the absolute value of a Fixed32..
| fInput | Value to get the absolute value of. |
Get the arctangent from the slope of two signed integers.
Taking two integers of like type (Two Fixed32, Int32 or Frac32) determine the atan2 value of the slope and return it as a Fixed32 in the range of - Burger::PiFixed32 to Burger::PiFixed32
| fInput1 | Numerator for the atan2 calculation | |
| fInput2 | Denominator for the atan2 calculation |
| Fixed32 BURGER_API Burger::FixedMath::CrossProduct2DSign | ( | Fixed32 | fInputX1, | |
| Fixed32 | fInputY1, | |||
| Fixed32 | fInputX2, | |||
| Fixed32 | fInputY2 | |||
| ) | [static] |
Return the sign of the result of a 2D cross product.
For the calculation to determine if a point is on the front or back of a line, a cross product is done and only whether if the result is greater or equal to zero is all that matters.
To perform this operation efficiently on 32 bit CPUs, the values are multiplied to make 64 bit results, the values are subtracted and only the upper 32 bits are returned and the caller only tests the sign of the result to get the decision if the point is in front or behind a line.
| fInputX1 | X coordinate of the first 2D point. | |
| fInputY1 | Y coordinate of the first 2D point. | |
| fInputX2 | X coordinate of the second 2D point. | |
| fInputY2 | Y coordinate of the second 2D point. |
Divide two 16.16 fixed point numbers.
Divide a 16.16 fixed point number by another 16.16 fixed point number without saturation or checking for division by zero..
| fInputNumerator | Signed value to divide | |
| fInputDenominator | Signed value to divide with |
| Fixed32 BURGER_API Burger::FixedMath::DivideSaturate | ( | Fixed32 | fInputNumerator, | |
| Fixed32 | fInputDenominator | |||
| ) | [static] |
Divide a 16.16 fixed point number with saturation.
Perform a signed division of two 32-bit fixed point numbers and return the fixed point result. If the answer exceeds the range allowable for a Fixed32 value, it will be saturated to the minimum and maximum bounds. Division by zero will return positive or negative maximums.
| fInputNumerator | Value to divide | |
| fInputDenominator | Value to divide with |
| Int32 Burger::FixedMath::FromFloat | ( | float | fInput | ) | [inline, static] |
Convert a single float to a Fixed32 using round to zero.
Convert a single precision floating point number to a Fixed32 using the round to zero fractional truncation
| fInput | A valid single precision floating point number. |
| void Burger::FixedMath::FromFloat | ( | Fixed32 * | pOutput, | |
| float | fInput | |||
| ) | [inline, static] |
Convert a single float to a Fixed32 using round to zero.
Convert a single precision floating point number to a Fixed32 using the round to zero fractional truncation and store it to memory
| pOutput | A valid pointer to a Fixed32 to receive the result. | |
| fInput | A valid single precision floating point number. |
| void Burger::FixedMath::FromFloatCeil | ( | Fixed32 * | pOutput, | |
| float | fInput | |||
| ) | [inline, static] |
Convert a single float to a Fixed32 using ceil().
Convert a single precision floating point number to a Fixed32 using the ceil() form of fractional truncation and store it to memory
| pOutput | A valid pointer to a Fixed32 to receive the result. | |
| fInput | A valid single precision floating point number. |
| Int32 Burger::FixedMath::FromFloatCeil | ( | float | fInput | ) | [inline, static] |
Convert a single float to a Fixed32 using ceil().
Convert a single precision floating point number to a Fixed32 using the ceil() form of fractional truncation
| fInput | A valid single precision floating point number. |
| void Burger::FixedMath::FromFloatFloor | ( | Fixed32 * | pOutput, | |
| float | fInput | |||
| ) | [inline, static] |
Convert a single float to a Fixed32 using floor().
Convert a single precision floating point number to a Fixed32 using the floor() form of fractional truncation and store it to memory
| pOutput | A valid pointer to a Fixed32 to receive the result. | |
| fInput | A valid single precision floating point number. |
| Int32 Burger::FixedMath::FromFloatFloor | ( | float | fInput | ) | [inline, static] |
Convert a single float to a Fixed32 using floor().
Convert a single precision floating point number to a Fixed32 using the floor() form of fractional truncation
| fInput | A valid single precision floating point number. |
| Int32 Burger::FixedMath::FromFloatNearest | ( | float | fInput | ) | [inline, static] |
Convert a single float to a Fixed32 using round to nearest.
Convert a single precision floating point number to a Fixed32 using the round to nearest fractional truncation
| fInput | A valid single precision floating point number. |
| void Burger::FixedMath::FromFloatNearest | ( | Fixed32 * | pOutput, | |
| float | fInput | |||
| ) | [inline, static] |
Convert a single float to a Fixed32 using round to nearest.
Convert a single precision floating point number to a Fixed32 using the round to nearest fractional truncation and store it to memory
| pOutput | A valid pointer to a Fixed32 to receive the result. | |
| fInput | A valid single precision floating point number. |
| Burger::FixedMath::FromInt | ( | Int32 | iInput | ) | [inline, static] |
Convert an Int32 into a Fixed32 value.
Convert an integer into a fixed point number. No bounds checking is performed so values that exceed 32767 or are less than -32768 will yield undefined results.
| iInput | Integer to convert |
Convert an Int32 into a Fixed32 value with saturation.
Convert an integer into a fixed point number. Bounds checking is performed so values that exceed 32767 or are less than -32768 will yield max and min values..
Examples of clamping:
| iInput | Integer to convert |
Multiply two 16.16 fixed point numbers.
Perform a signed multiplication of two 32-bit fixed point numbers and return the fixed point result. No error checking is performed, so overflow or underflow conditions yield undefined results.
| fInputMulA | First signed value to multiply | |
| fInputMulB | Second signed value to multiply |
| Fixed32 BURGER_API Burger::FixedMath::MultiplySaturate | ( | Fixed32 | fInputMulA, | |
| Fixed32 | fInputMulB | |||
| ) | [static] |
Multiply two 16.16 fixed point numbers with saturation.
Perform a signed multiplication of two 32-bit fixed point numbers and return the fixed point result. If the value exceeds the range allowable for a Fixed32 value, it will be saturated to the minimum and maximum bounds.
| fInputMulA | First signed value to multiply | |
| fInputMulB | Second signed value to multiply |
| Burger::FixedMath::Reciprocal | ( | Fixed32 | fInput | ) | [inline, static] |
Return the reciprocal of a fixed point number.
Divide a 16.16 fixed point number by 1.0f in fixed point. If the input value is negative epsilon (0xFFFFFFFF), return 0x8000000. If the input is equal to 0 or positive epsilon (0x1), then return 0x7ffffff. This has the effect of saturating the output and leaving no output as undefined.
| fInput | Fixed32 value to convert to a reciprocal. |
Get the square root of a Fixed32.
Return the square root of a Fixed32 and return the Fixed32 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. |
1.7.1