From: Babak A. <ba...@ho...> - 2001-12-18 23:39:31
|
Hi all, I'm having major problems with INT32 vars. It all started when I realized I wasn't getting accurate results with division of INT32 vars. So I wrote the following snippet to try and isolate the problem and found the following results so far: This function, div, divides nNumA by nNumB by bit-shifting: INT32 div(INT32 nNumA, INT32 nNumB) { INT32 nTemp; /* No division by zero! */ if (nNumB != 0) nTemp = nNumA >> nNumB; return nTemp; } void main() { INT32 x; /*The if statement only works when x is declared INT16 */ x = div(10, 2); if (x == (INT32)(10 >> 2) ) gprintf("equal."); else gprintf("not equal."); } In main() I just use the function to divide 10 by 2 and store the result in x. Then I do a comparison with the result and the equivilent shift in the IF statement. In the above code it'll always result in "not equal" but if I use INT16 it'll be okay. Furthermore various combinations of INT16 and INT32 in function div and main work fine as long as x is ALWAYS declared as INT16, BUT if I ever declare x in main() as INT32 the comparison in the IF statement fails. Sorry if this all sounds confusing but anyone have any insight? Tnx, Babak. _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com |