Defines | |
#define | FIX_SHIFT 8 |
#define | FIX_SCALE ( 1<<FIX_SHIFT ) |
#define | FIX_MASK ( FIX_SCALE-1 ) |
#define | FIX_SCALEF ( (float)FIX_SCALE ) |
#define | FIX_SCALEF_INV ( 1.0/FIX_SCALEF ) |
#define | FIX_ONE FIX_SCALE |
#define | FX_RECIPROCAL(a, fp) ( ((1<<(fp))+(a)-1)/(a) ) |
Get the fixed point reciprocal of a, in fp fractional bits. | |
#define | FX_RECIMUL(x, a, fp) ( ((x)*((1<<(fp))+(a)-1)/(a))>>(fp) ) |
Perform the division x/ a by reciprocal multiplication. | |
Functions | |
INLINE FIXED | int2fx (int d) |
Convert an integer to fixed-point. | |
INLINE FIXED | float2fx (float f) |
Convert a float to fixed-point. | |
INLINE u32 | fx2uint (FIXED fx) |
Convert a FIXED point value to an unsigned integer (orly?). | |
INLINE u32 | fx2ufrac (FIXED fx) |
Get the unsigned fractional part of a fixed point value (orly?). | |
INLINE int | fx2int (FIXED fx) |
Convert a FIXED point value to an signed integer. | |
INLINE float | fx2float (FIXED fx) |
Convert a fixed point value to floating point. | |
INLINE FIXED | fxadd (FIXED fa, FIXED fb) |
Add two fixed point values. | |
INLINE FIXED | fxsub (FIXED fa, FIXED fb) |
Subtract two fixed point values. | |
INLINE FIXED | fxmul (FIXED fa, FIXED fb) |
Multiply two fixed point values. | |
INLINE FIXED | fxdiv (FIXED fa, FIXED fb) |
Divide two fixed point values. | |
INLINE FIXED | fxmul64 (FIXED fa, FIXED fb) |
Multiply two fixed point values using 64bit math. | |
INLINE FIXED | fxdiv64 (FIXED fa, FIXED fb) |
Divide two fixed point values using 64bit math. |
#define FIX_SHIFT 8 |
#define FX_RECIMUL | ( | x, | |||
a, | |||||
fp | ) | ( ((x)*((1<<(fp))+(a)-1)/(a))>>(fp) ) |
Perform the division x/ a by reciprocal multiplication.
Division is slow, but you can approximate division by a constant by multiplying with its reciprocal: x/a vs x*(1/a). This routine gives the reciprocal of a as a fixed point number with fp fractional bits.
a | Value to take the reciprocal of. | |
fp | Number of fixed point bits |
Rules for safe reciprocal division, using n = 2fp and m = (n+a-1)/a (i.e., rounding up)
#define FX_RECIPROCAL | ( | a, | |||
fp | ) | ( ((1<<(fp))+(a)-1)/(a) ) |
Get the fixed point reciprocal of a, in fp fractional bits.
a | Value to take the reciprocal of. | |
fp | Number of fixed point bits |