I) I'll use rafb/paste now, it's just easier to read. MUL and DIV now have a range check (set to MIN and MAX values) und use long long as intermediate. ADD und SUB still wrap around. Fixed Point Class C++
II) I keep the question if parameter passing by value or reference is better to you guys. I don't feel like reading gcc's ARM ASM. In case we have tp bloat the class more, pass by refernece becomes a must anyway.
III) I decided to fix magnitude.fraction to 16.16 for now and make it variable after everything works.
IV) I use normaly a degree sinus LUT with 360 fixed entries. This need rad->degree conversion or natively working with degrees what I do anyway. A precision of 1 degree should be enough for 2D stuff. Any comment on this or simple ideas to have a small but precise LUT(s)?
V) I did not understand the square root code posted earlier, I'll look for solution (any hints?). But a sqrt() would need a NaN value (root from negative value) as DIV by zero should already have. As we are on it, saturation anyone?
I think a solution is to assume that sqrt always operates on positive numbers... if you're taking a square root of a negative, chances are there's already a problem. Division by zero could return the maximum representable value, and again, it's one of those things you try to avoid anyway.
IV) I use normaly a degree sinus LUT with 360 fixed entries. This need rad->degree conversion or natively working with degrees what I do anyway. A precision of 1 degree should be enough for 2D stuff. Any comment on this or simple ideas to have a small but precise LUT(s)?
You only need a quarter revolution for sine. (and then reuse the same table for cosine) I recommend using a power of 2 instead of 360 (I use 1024), because it makes some of the math slightly more efficient. You still need conversion from radians to revolutions, but it's just pi and shifting.
synkro posted on Oct 20 2006 at 05:00 AM said:
V) I did not understand the square root code posted earlier, I'll look for solution (any hints?). But a sqrt() would need a NaN value (root from negative value) as DIV by zero should already have. As we are on it, saturation anyone?
Division by zero should automatically throw an exception or signal or something. I think the most common thing to do with sqrt of negative is to just short out and return 0. It might be more interesting to treat the number as unsigned and get an extra bit of range.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.