summaryrefslogtreecommitdiff
path: root/digital/avr/modules/math/fixed/fixed.h
diff options
context:
space:
mode:
authorNicolas Schodet2009-08-24 21:27:30 +0200
committerNicolas Schodet2009-08-24 21:27:30 +0200
commit7bf92a1ee80c988f736d4f3f1a5a8edbca74456e (patch)
tree441643baab65dae35ab31618f2969e0015113c81 /digital/avr/modules/math/fixed/fixed.h
parent6ed931bd5a6978bf69303d4eb69eab406983fbf1 (diff)
* digital/avr/modules/math/fixed:
- round division result (closes #96). - changed macros to inlined.
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