summaryrefslogtreecommitdiff
path: root/digital/avr/modules/math/fixed/fixed.h
diff options
context:
space:
mode:
Diffstat (limited to 'digital/avr/modules/math/fixed/fixed.h')
-rw-r--r--digital/avr/modules/math/fixed/fixed.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/digital/avr/modules/math/fixed/fixed.h b/digital/avr/modules/math/fixed/fixed.h
index 7bc45d6a..89aa5ba4 100644
--- a/digital/avr/modules/math/fixed/fixed.h
+++ b/digital/avr/modules/math/fixed/fixed.h
@@ -54,13 +54,23 @@ fixed_div_f824 (int32_t a, int32_t b);
#else /* HOST */
/** Multiply f8.24 by f8.24, return f8.24. */
-#define fixed_mul_f824(a, b) \
- (((int64_t) (int32_t) (a) * (int64_t) (int32_t) (b) \
- + 0x800000LL) >> 24)
+extern inline
+int32_t
+fixed_mul_f824 (int32_t a, int32_t b)
+{
+ return ((int64_t) a * b + 0x800000) >> 24;
+}
/** Divide f8.24 by f8.24, return f8.24. */
-#define fixed_div_f824(a, b) \
- (((int64_t) (int32_t) (a) << 24) / (int64_t) (int32_t) (b))
+extern inline
+int32_t
+fixed_div_f824 (int32_t a, int32_t b)
+{
+ if ((a ^ b) >= 0)
+ return (((int64_t) a << 24) + b / 2) / b;
+ else
+ return (((int64_t) a << 24) - b / 2) / b;
+}
#endif