Comments (5)
Fix for the general 64bit cases:
Index: fix16.c
===================================================================
--- fix16.c (revision 51)
+++ fix16.c (working copy)
@@ -35,7 +35,7 @@
#ifndef FIXMATH_NO_64BIT
int64_t tempResult = ((int64_t)inArg0 * (int64_t)inArg1);
#ifndef FIXMATH_NO_ROUNDING
- tempResult += (fix16_one >> 1);
+ tempResult += (tempResult > 0) ? (fix16_one >> 1) : -(fix16_one >> 1);
#endif
tempResult >>= 16;
return tempResult;
@@ -97,7 +97,7 @@
int64_t tempResult = inArg0;
tempResult <<= 16;
#ifndef FIXMATH_NO_ROUNDING
- tempResult += (inArg1 >> 1);
+ tempResult += (tempResult > 0) ? (inArg1 >> 1) : -(inArg1 >> 1);
#endif
tempResult /= inArg1;
return tempResult;
Original comment by Petteri.Aimonen
on 29 Nov 2011 at 8:24
from libfixmath.
Actually, for it to work also for result = 0:
Index: fix16.c
===================================================================
--- fix16.c (revision 51)
+++ fix16.c (working copy)
@@ -35,7 +35,7 @@
#ifndef FIXMATH_NO_64BIT
int64_t tempResult = ((int64_t)inArg0 * (int64_t)inArg1);
#ifndef FIXMATH_NO_ROUNDING
- tempResult += (fix16_one >> 1);
+ tempResult += (tempResult >= 0) ? (fix16_one >> 1) : -(fix16_one >> 1);
#endif
tempResult >>= 16;
return tempResult;
@@ -97,7 +97,7 @@
int64_t tempResult = inArg0;
tempResult <<= 16;
#ifndef FIXMATH_NO_ROUNDING
- tempResult += (inArg1 >> 1);
+ tempResult += (tempResult >= 0) ? (inArg1 >> 1) : -(inArg1 >> 1);
#endif
tempResult /= inArg1;
return tempResult;
Looks like we could use some validation framework :)
Original comment by Petteri.Aimonen
on 29 Nov 2011 at 8:36
from libfixmath.
Agreed, we have some tests but they clearly aren't even close to exhaustive.
Would you be interested in joining the project? There are no expectations of
work but it means you can make any reasonable changes you'd like to improve the
codebase.
Original comment by [email protected]
on 30 Nov 2011 at 10:02
from libfixmath.
I'm currently working on a fix16_t based matrix algebra library, so yes, I
would be interested.
Original comment by Petteri.Aimonen
on 30 Nov 2011 at 10:17
from libfixmath.
This issue was closed by revision r52.
Original comment by Petteri.Aimonen
on 26 Jan 2012 at 3:43
- Changed state: Fixed
from libfixmath.
Related Issues (20)
- div defect HOT 2
- Problem with sdiv.. HOT 19
- C++ Fix16 cast operators should be const. HOT 1
- Optimize caching on trig functions
- Unittests fail on division, on x86_64 architecture. HOT 10
- Incorrect conversions from int to float and more HOT 4
- compiler error after setting #define FIXMATH_NO_OVERFLOW HOT 2
- left shift count >= width of type HOT 1
- >= 0 comparison might be more efficient than > 0 comparison HOT 1
- atan2 incorrect HOT 5
- fix16_str_unittests fails (MSYS/windows) HOT 1
- FIXMATH_FAST_SIN gives rounding error HOT 1
- libfixmath for cortex m0 HOT 2
- fix16_div bug due to __builtin_clzl HOT 4
- Probably error in log2 functions test for skipping decimal part
- Unary minus on unsigned type HOT 1
- 32-bit multiplication seems to be way off for some values HOT 3
- Fix16(const fix16_t inValue) should be removed
- lerp overflows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libfixmath.