??? 08/10/07 22:45 Read: times |
#143080 - Try this, can be better Responding to: ???'s previous message |
This can be so much complicated part of code for compiler:
tmp = 65536 - (10 * AxisAngle + 460) * 221184 / 120000; //that is, by removing the two zeros TH = tmp / 256; TL = tmp - TH * 256; I have some experience with getting better result and eliminating anomally with divide formula to smaller part and also expliciting conversion like this: // temporarily variables float tmp_float = 0; unsigned int tmp = 0; // your following formula: // tmp = 65536 - (10 * AxisAngle + 460) * 221184 / 120000 // can be rewrite by this: tmp_float = (float)AxisAngle * (float)10; tmp_float += (float)460; // this is equal for tmp_float = tmp_float + (float)460; tmp_float *= (float)3456; // this is equal for tmp_float = tmp_float * (float)3456; tmp_float /= (float)1875; // this is equal for tmp_float = tmp_float / (float)1875; // 3456/1875 is equal to 221184/120000 but smaller numbers tmp_float = (float)65536 - tmp_float; // finally you can use here some of round functions to get... // ...better result or simplify conversion like this: tmp = (unsigned int)tmp_float; // after this it is better using bit rotation rutines instead... // ...of dividing and substracting TH = (unsigned char)(tmp >> 8); TL = (unsigned char)tmp; // or TL = (unsigned char)(tmp & 0xFF); ... This can be helpfull in other cases not just in this one. Keep this on your mind and I think you will have less problem with compiler anomally :) Good luck. Michal |