From 42b0ff9d170334f89e1d6b824b77251537c9abfb Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Tue, 15 Oct 2024 15:13:40 +0100 Subject: [PATCH] define basic fixed-point arithmetic operations --- src/threads/fixed-point.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/threads/fixed-point.h b/src/threads/fixed-point.h index 201ccb4..0270b55 100644 --- a/src/threads/fixed-point.h +++ b/src/threads/fixed-point.h @@ -6,4 +6,18 @@ #define NUM_FRAC_BITS 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