comment fixed point arithmetic header
This commit is contained in:
@@ -7,20 +7,25 @@
|
|||||||
#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 */
|
/* Fixed Point Arithmetic conversion operations */
|
||||||
|
/* Converts an integer n to a fixed point number */
|
||||||
#define INT_TO_FP(n) ((n) * (CONVERSION_CONST))
|
#define INT_TO_FP(n) ((n) * (CONVERSION_CONST))
|
||||||
|
|
||||||
|
/* Handles conversion of fixed point to integer. First version truncates, second one rounds */
|
||||||
#define FLOOR_FP_TO_INT(x) ((x) / (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))
|
#define ROUNDING_FP_TO_INT(x) ((x) >= 0 ? ((x) + ((CONVERSION_CONST) / 2)) : ((x) - ((CONVERSION_CONST) / 2))
|
||||||
|
|
||||||
/* Fixed Point Arithmetic addition operations */
|
/* Fixed Point Arithmetic addition operations */
|
||||||
#define FP_ADD(x, y) ((x) + (y))
|
#define FP_ADD(x, y) ((x) + (y))
|
||||||
#define FP_SUBTRACT(x, y) ((x) - (y))
|
#define FP_SUBTRACT(x, y) ((x) - (y))
|
||||||
|
/* Addition and Subtraction but between a fixed point and an integer */
|
||||||
#define FP_ADD_INT(x, n) ((x) + ((n) * (CONVERSION_CONST)))
|
#define FP_ADD_INT(x, n) ((x) + ((n) * (CONVERSION_CONST)))
|
||||||
#define FP_SUBTRACT_INT(x, n) ((x) - ((n) * (CONVERSION_CONST)))
|
#define FP_SUBTRACT_INT(x, n) ((x) - ((n) * (CONVERSION_CONST)))
|
||||||
|
|
||||||
/* Fixed Point Arithmetic multiplication operations */
|
/* Fixed Point Arithmetic multiplication operations */
|
||||||
#define FP_MULTIPLY(x, y) ((int64_t)(x)) * (y) / (CONVERSION_CONST)
|
#define FP_MULTIPLY(x, y) ((int64_t)(x)) * (y) / (CONVERSION_CONST)
|
||||||
#define FP_MULTIPLY_INT(x, n) ((x) * (n))
|
|
||||||
#define FP_DIVIDE(x, y) ((int64_t)(x)) * (CONVERSION_CONST) / (y)
|
#define FP_DIVIDE(x, y) ((int64_t)(x)) * (CONVERSION_CONST) / (y)
|
||||||
|
/* Multiplication and division but between a fixed point and an integer */
|
||||||
|
#define FP_MULTIPLY_INT(x, n) ((x) * (n))
|
||||||
#define FP_DIVIDE_INT(x, n) ((x) / (n))
|
#define FP_DIVIDE_INT(x, n) ((x) / (n))
|
||||||
|
|
||||||
#endif //FIXED_POINT_H
|
#endif //FIXED_POINT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user