From 10af3a6c608432e9f51562f6a67e873cc111ea50 Mon Sep 17 00:00:00 2001 From: "Petteri.Aimonen" Date: Thu, 30 Aug 2012 16:52:52 +0000 Subject: Add shorthand macro F16() for defining numeric constants --- libfixmath/fix16.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libfixmath/fix16.h b/libfixmath/fix16.h index 3b41d2c..6f3599b 100644 --- a/libfixmath/fix16.h +++ b/libfixmath/fix16.h @@ -75,7 +75,16 @@ static inline fix16_t fix16_from_dbl(double a) return (fix16_t)temp; } +/* Macro for defining fix16_t constant values. + The functions above can't be used from e.g. global variable initializers, + and their names are quite long also. This macro is useful for constants + springled alongside code, e.g. F16(1.234). + Note that the argument is evaluated multiple times, and also otherwise + you should only use this for constant values. For runtime-conversions, + use the functions above. +*/ +#define F16(x) ((fix16_t)(((x) >= 0) ? ((x) * 65536.0 + 0.5) : ((x) * 65536.0 - 0.5))) static inline fix16_t fix16_abs(fix16_t x) { return (x < 0 ? -x : x); } -- cgit v1.2.3