aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflatmush <flatmush@d3e1167c-abe1-51d5-8199-f9061ebe54e4>2011-03-03 11:51:10 +0000
committerflatmush <flatmush@d3e1167c-abe1-51d5-8199-f9061ebe54e4>2011-03-03 11:51:10 +0000
commit5fd33d1f980dc32467bef87b31c6bacd30cab740 (patch)
tree5119e294df088ebe43eecddd76d3768bcc3b38ab
parentcc1e97463ef6c5d5cef55191e203c60171f472b3 (diff)
downloadlibfixmath-5fd33d1f980dc32467bef87b31c6bacd30cab740.tar.gz
Updated lerp6 and lerp16 (LinEar inteRPolation) to use the new int64 header so that it can be used with FIXMATH_NO_64BIT.
Included "int64.h" in "fixmath.h" so that 64-bit integer support is now part of the libraries functionality.
-rw-r--r--libfixmath/fix16.c21
-rw-r--r--libfixmath/fix16.h2
-rw-r--r--libfixmath/fixmath.h1
3 files changed, 12 insertions, 12 deletions
diff --git a/libfixmath/fix16.c b/libfixmath/fix16.c
index d162554..91c5841 100644
--- a/libfixmath/fix16.c
+++ b/libfixmath/fix16.c
@@ -1,4 +1,5 @@
#include "fix16.h"
+#include "int64.h"
@@ -219,23 +220,21 @@ fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1) {
-#ifndef FIXMATH_NO_64BIT
fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract) {
- int64_t tempOut;
- tempOut = ((int64_t)inArg0 * (256 - inFract));
- tempOut += ((int64_t)inArg1 * inFract);
- tempOut >>= 8;
- return (fix16_t)tempOut;
+ int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract));
+ tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
+ tempOut = int64_shift(tempOut, -8);
+ return (fix16_t)int64_lo(tempOut);
}
fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract) {
- int64_t tempOut;
- tempOut = ((int64_t)inArg0 * (fix16_one - inFract));
- tempOut += ((int64_t)inArg1 * inFract);
- tempOut >>= 16;
- return (fix16_t)tempOut;
+ int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract));
+ tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
+ tempOut = int64_shift(tempOut, -16);
+ return (fix16_t)int64_lo(tempOut);
}
+#ifndef FIXMATH_NO_64BIT
fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract) {
int64_t tempOut;
tempOut = ((int64_t)inArg0 * (0 - inFract));
diff --git a/libfixmath/fix16.h b/libfixmath/fix16.h
index 300bb72..dfb8cb7 100644
--- a/libfixmath/fix16.h
+++ b/libfixmath/fix16.h
@@ -72,11 +72,11 @@ extern fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1);
-#ifndef FIXMATH_NO_64BIT
/*! Returns the linear interpolation: (inArg0 * (1 - inFract)) + (inArg1 * inFract)
*/
extern fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract);
extern fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract);
+#ifndef FIXMATH_NO_64BIT
extern fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract);
#endif
diff --git a/libfixmath/fixmath.h b/libfixmath/fixmath.h
index ed35f7d..cd0d20a 100644
--- a/libfixmath/fixmath.h
+++ b/libfixmath/fixmath.h
@@ -12,6 +12,7 @@ extern "C"
*/
#include "uint32.h"
+#include "int64.h"
#include "fract32.h"
#include "fix16.h"