#146214 - keldon - Fri Nov 30, 2007 5:56 pm
Are you remembering to shift afterwards, and keeping tabs on where the point is after an operation? If it is overflowing after the shift then you may need to work with less magnitude and more fractional bits; at least after the operation.
#146523 - kusma - Wed Dec 05, 2007 10:39 am
If FP_SCALE is (1 << 13), my guess would be either because of programming semantics (the compiler generates the same code anyway -- but only for unsigned integer dividends), or to fix the negative value case (with shifts, negative values gets off-by-one compared to the division).
One could argue that conceptually it's a scale, not some bit-manipulation which is what the shift operator is mainly for. But to be honest, I think fixed point math is kind of a special case and that using shifts directly often is clearer since it's the more common way of doing it. And since it's slightly faster (usually compiles to something like "x >> y" instead of "x >> y + (x < 0 ? 1 : 0)") and the error is "acceptable" (1 ULP), I just find the shift even more appealing.
#146529 - Lino - Wed Dec 05, 2007 11:55 am
I have said if you have problems with right shift of signed inetger, you can use the asr instruction. Otherwise the logical right shift puts all zeros in the top, you lose the sign.