diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2021-10-24 02:42:00 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2021-10-24 02:42:00 +0200 |
| commit | ac37834fe63683619b1a0fa6692f56e419badb5e (patch) | |
| tree | 9e452a81fe4d785d0ce9c8015947630c4706182b | |
| parent | d9068688be61ea6295a3b61f9428ceddf7e1467d (diff) | |
fix16.h: provide fix16_from-like compile-time macros
| -rwxr-xr-x | libfixmath/fixmath/fix16.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libfixmath/fixmath/fix16.h b/libfixmath/fixmath/fix16.h index a2a49b1..d5acb81 100755 --- a/libfixmath/fixmath/fix16.h +++ b/libfixmath/fixmath/fix16.h @@ -42,6 +42,12 @@ static inline fix16_t fix16_from_int(int a) { return a * fix16_one; } static inline float fix16_to_float(fix16_t a) { return (float)a / fix16_one; }
static inline double fix16_to_dbl(fix16_t a) { return (double)a / fix16_one; }
+/* Static inline functions cannot be used to determine compile-time values,
+ * so use this expression instead if needed. */
+#define FIX16_C_FROM_INT(a) ((a) * fix16_one)
+#define FIX16_C_FROM_FLOAT(a) (((float)(a) * fix16_one) >= 0 ? \
+ (((float)(a) * fix16_one)) + 0.5f : ((float)(a) * fix16_one) - 0.5f)
+
static inline int fix16_to_int(fix16_t a)
{
#ifdef FIXMATH_NO_ROUNDING
|
