#176039 - LOst? - Sun Mar 27, 2011 12:33 pm
I want to understand why it is sometimes good to do this in a fixed point multiplication (example uses n.12 fixed point):
And sometimes, it is not good at all! It all depends on the situation. But I haven't been able to figure out why. And I have never seen any explainations to it.
If you don't understand at this point, I don't know if you should waste time trying to figure it out. I am mainly asking if some of you program this way, and know why you do it :P
Now, according to THE source that I learned this from, it also uses a simular thing when trying to figure out where on a rotated line you are:
It yields a different result from how I used to do things:
I am so damn curious to why THE source I learned this from uses this kind of rounding!
I am trying to rewrite my own slope formula to be compatibe with the "rounded?" one, and the problem is that "Slope" has already been pre-calculated, so that I can just do "Pos * Slope" to get the "Result" without having to do a divide. But I am having trouble when trying to get the same result as the OTHER one, as it multiplies Pos with YDir, applies that 0.5f rounding, etc, etc.
The biggest difference is +/- 1 unit, and is hardly visible anyway in my case. But I am still curious!
_________________
Exceptions are fun
Code: |
Result = (A * B + 0x800) >> 12; /****Testing****** A = 0x2000; // 2.0f * 4096.f B = 0x0800; // 0.5f * 4096.f C = A * B; C == 0x1000000; // 1.f * 4096.f * 4096.f C += 0x800; // 0.5f * 4096.f C == 0x1000800; // ------------------Why?? C >>= 12; // (float) C / 4096.f Result = C; Result = 0x1000; // 1.f * 4096.f ****************/ |
And sometimes, it is not good at all! It all depends on the situation. But I haven't been able to figure out why. And I have never seen any explainations to it.
If you don't understand at this point, I don't know if you should waste time trying to figure it out. I am mainly asking if some of you program this way, and know why you do it :P
Now, according to THE source that I learned this from, it also uses a simular thing when trying to figure out where on a rotated line you are:
Code: |
A = Pos * YDir + 0x800; B = ((A << 12) / XDir) + 0x800; Result = B >> 12; |
It yields a different result from how I used to do things:
Code: |
Slope = (YDir << 12) / XDir; Result = (Pos * Slope) >> 12; |
I am so damn curious to why THE source I learned this from uses this kind of rounding!
I am trying to rewrite my own slope formula to be compatibe with the "rounded?" one, and the problem is that "Slope" has already been pre-calculated, so that I can just do "Pos * Slope" to get the "Result" without having to do a divide. But I am having trouble when trying to get the same result as the OTHER one, as it multiplies Pos with YDir, applies that 0.5f rounding, etc, etc.
The biggest difference is +/- 1 unit, and is hardly visible anyway in my case. But I am still curious!
_________________
Exceptions are fun