define basic fixed-point arithmetic operations
This commit is contained in:
@@ -6,4 +6,18 @@
|
|||||||
#define NUM_FRAC_BITS 20
|
#define NUM_FRAC_BITS 20
|
||||||
#define CONVERSION_CONST 1 << NUM_FRAC_BITS /* f = 2^q, (2^20) */
|
#define CONVERSION_CONST 1 << NUM_FRAC_BITS /* f = 2^q, (2^20) */
|
||||||
|
|
||||||
|
/* Fixed Point Arithmetic conversion operations */
|
||||||
|
#define INT_TO_FP(n) ((n) * (CONVERSION_CONST))
|
||||||
|
#define FLOOR_FP_TO_INT(x) ((x) / (CONVERSION_CONST))
|
||||||
|
#define ROUNDING_FP_TO_INT(x) ((x) >= 0 ? ((x) + ((CONVERSION_CONST) / 2)) : ((x) - ((CONVERSION_CONST) / 2))
|
||||||
|
|
||||||
|
/* Fixed Point Arithmetic addition operations */
|
||||||
|
#define FP_ADD(x, y) ((x) + (y))
|
||||||
|
#define FP_SUBTRACT(x, y) ((x) - (y))
|
||||||
|
#define FP_ADD_INT(x, n) ((x) + ((n) * (CONVERSION_CONST)))
|
||||||
|
#define FP_SUBTRACT_INT(x, n) ((x) - ((n) * (CONVERSION_CONST)))
|
||||||
|
|
||||||
|
/* Fixed Point Arithmetic multiplication operations */
|
||||||
|
|
||||||
|
|
||||||
#endif //FIXED_POINT_H
|
#endif //FIXED_POINT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user