Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
These utility functions are can be used for fixed point decimal math.
q24_8 has 24 bits of signed integer and 8 bits of decimal. The integer range is from -8388608 to 8388607 and the smallest decimal resolution is 1/256.
q16_16 and q8_24 typedefs are also provided, but function macros aren't. Use with caution if more decimal precision is required.
vec_q24_8 is a vector type for q24_8. Fixed point vector math functions are provided and start with 'fpv.'
No initialization or deinitialization is required.
Go to the source code of this file.
Data Structures | |
struct | vec_q24_8 |
A 2D vector with q24_8 numbers. More... | |
Macros | |
#define | FRAC_BITS 8 |
8 fractional bits for q24_8 | |
#define | Q24_8_DECI_MASK ((1 << FRAC_BITS) - 1) |
A mask for the fractional part of a q24_8. | |
#define | Q24_8_WHOLE_MASK (~Q24_8_DECI_MASK) |
A mask for the integer part of a q24_8. | |
#define | Q16_16_FRAC_BITS 16 |
8 fractional bits for q16_16 | |
#define | Q16_16_DECI_MASK ((1 << Q16_16_FRAC_BITS) - 1) |
A mask for the fractional part of a q16_16. | |
#define | Q16_16_WHOLE_MASK (~Q16_16_DECI_MASK) |
A mask for the integer part of a q16_16. | |
#define | Q8_24_FRAC_BITS 24 |
8 fractional bits for q8_24 | |
#define | Q8_24_DECI_MASK ((1 << Q8_24_FRAC_BITS) - 1) |
A mask for the fractional part of a q8_24. | |
#define | Q8_24_WHOLE_MASK (~Q8_24_DECI_MASK) |
A mask for the integer part of a q8_24. | |
#define | FP_MATH_DEFINES |
#define | TO_FX(in) ((in) * (1 << FRAC_BITS)) |
Convert an integer to a q24_8. | |
#define | FROM_FX(in) ((in) >> FRAC_BITS) |
Convert a q24_8 to an integer. | |
#define | ADD_FX(a, b) ((a) + (b)) |
Add two q24_8 numbers together. | |
#define | SUB_FX(a, b) ((a) - (b)) |
Subtract a q24_8 from another. | |
#define | MUL_FX(a, b) (((a) * (b)) >> FRAC_BITS) |
Multiply two q24_8. | |
#define | DIV_FX(a, b) (((a) << FRAC_BITS) / (b)) |
Divide a q24_8 by another. | |
#define | FLOOR_FX(a) ((a) & (~((1 << FRAC_BITS) - 1))) |
Find the floor of a q24_8. | |
#define | TO_FX_FRAC(num, denom) DIV_FX(num, denom) |
Convert an integer fraction to q24_8. | |
Typedefs | |
typedef int16_t | q8_8 |
8 bits integer, 8 bits fraction | |
typedef int32_t | q24_8 |
24 bits integer, 8 bits fraction | |
typedef int32_t | q16_16 |
16 bits integer, 16 bits fraction | |
typedef int32_t | q8_24 |
8 bits integer, 24 bits fraction | |
typedef uint16_t | uq8_8 |
unsigned 8 bits integer, 8 bits fraction | |
typedef uint32_t | uq24_8 |
unsigned 24 bits integer, 8 bits fraction | |
typedef uint32_t | uq16_16 |
unsigned 16 bits integer, 16 bits fraction | |
typedef uint32_t | uq8_24 |
unsigned 8 bits integer, 24 bits fraction | |
Functions | |
void | fastNormVec (q24_8 *xp, q24_8 *yp) |
Quickly normalize a q24_8 vector, in-place. | |
vec_q24_8 | fpvAdd (vec_q24_8 a, vec_q24_8 b) |
Add two vectors. | |
vec_q24_8 | fpvSub (vec_q24_8 a, vec_q24_8 b) |
Subtract two vectors. | |
vec_q24_8 | fpvMulSc (vec_q24_8 vec, q24_8 scalar) |
Multiply a vector by a scalar. | |
vec_q24_8 | fpvDivSc (vec_q24_8 vec, q24_8 scalar) |
Divide a vector by a scalar. | |
q24_8 | fpvDot (vec_q24_8 a, vec_q24_8 b) |
Compute the dot product of two vectors. | |
q24_8 | fpvSqMag (vec_q24_8 a) |
Compute the squared magnitude of a vector. | |
vec_q24_8 | fpvNorm (vec_q24_8 vec) |
Normalize and return a vector. | |
float | fixToFloat (q24_8 fx) |
Convert a q24_8 to floating point. | |
struct vec_q24_8 |
#define FRAC_BITS 8 |
8 fractional bits for q24_8
#define Q24_8_DECI_MASK ((1 << FRAC_BITS) - 1) |
A mask for the fractional part of a q24_8.
#define Q24_8_WHOLE_MASK (~Q24_8_DECI_MASK) |
A mask for the integer part of a q24_8.
#define Q16_16_FRAC_BITS 16 |
8 fractional bits for q16_16
#define Q16_16_DECI_MASK ((1 << Q16_16_FRAC_BITS) - 1) |
A mask for the fractional part of a q16_16.
#define Q16_16_WHOLE_MASK (~Q16_16_DECI_MASK) |
A mask for the integer part of a q16_16.
#define Q8_24_FRAC_BITS 24 |
8 fractional bits for q8_24
#define Q8_24_DECI_MASK ((1 << Q8_24_FRAC_BITS) - 1) |
A mask for the fractional part of a q8_24.
#define Q8_24_WHOLE_MASK (~Q8_24_DECI_MASK) |
A mask for the integer part of a q8_24.
#define FP_MATH_DEFINES |
#define TO_FX | ( | in | ) | ((in) * (1 << FRAC_BITS)) |
Convert an integer to a q24_8.
in | The integer to convert to q24_8 |
#define FROM_FX | ( | in | ) | ((in) >> FRAC_BITS) |
Convert a q24_8 to an integer.
in | The q24_8 to convert to integer |
#define ADD_FX | ( | a, | |
b ) ((a) + (b)) |
Add two q24_8 numbers together.
a | An operand |
b | The other operand |
#define SUB_FX | ( | a, | |
b ) ((a) - (b)) |
Subtract a q24_8 from another.
a | The number to subtract from |
b | The number to subtract |
#define MUL_FX | ( | a, | |
b ) (((a) * (b)) >> FRAC_BITS) |
Multiply two q24_8.
a | An operand |
b | The other operand |
#define DIV_FX | ( | a, | |
b ) (((a) << FRAC_BITS) / (b)) |
Divide a q24_8 by another.
a | The numerator |
b | The denominator |
#define FLOOR_FX | ( | a | ) | ((a) & (~((1 << FRAC_BITS) - 1))) |
Find the floor of a q24_8.
a | The number to floor |
#define TO_FX_FRAC | ( | num, | |
denom ) DIV_FX(num, denom) |
Convert an integer fraction to q24_8.
num | The numerator |
denom | The denominator |
typedef int16_t q8_8 |
8 bits integer, 8 bits fraction
typedef int32_t q24_8 |
24 bits integer, 8 bits fraction
typedef int32_t q16_16 |
16 bits integer, 16 bits fraction
typedef int32_t q8_24 |
8 bits integer, 24 bits fraction
typedef uint16_t uq8_8 |
unsigned 8 bits integer, 8 bits fraction
typedef uint32_t uq24_8 |
unsigned 24 bits integer, 8 bits fraction
typedef uint32_t uq16_16 |
unsigned 16 bits integer, 16 bits fraction
typedef uint32_t uq8_24 |
unsigned 8 bits integer, 24 bits fraction
Quickly normalize a q24_8 vector, in-place.
xp | The X component of the vector, normalized in-place |
yp | The Y component of the vector, normalized in-place |
Add two vectors.
a | A vector to add |
b | The other vector to add |
Subtract two vectors.
a | A vector to subtract from |
b | The other vector to subtract |
Multiply a vector by a scalar.
vec | A vector multiply |
scalar | A scalar to multiply the vector by |
Divide a vector by a scalar.
vec | A vector divide |
scalar | A scalar to divide the vector by |
Compute the dot product of two vectors.
a | A vector to dot |
b | The other vector to dot |
Compute the squared magnitude of a vector.
a | The vector to compute the squared magnitude of |
Normalize and return a vector.
vec | The vector to normalize |
float fixToFloat | ( | q24_8 | fx | ) |
Convert a q24_8 to floating point.
fx | Fixed point input |