We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I need a 100% accurate division of any tow 32 bit numbers. So I am using the following code and the (/) operator. However I notice that results are not accurate when the Den (denominator) is shorter that 32 bit. For example (98765432/01234567) gives 120 where as the correct answer is 80. Can anyone tell me why ? Is something in my code incorrect More important, if this is not a bug, how to fix it ?
Incidentally, I cannot use Printf function so I am using a union function to map the long int variables into 4 unsigned char and the Display the char via a serial port. I don't think that process has introduced any errors in the calculations.
Thanks.
Bhal Tulpule
unsigned long int xdata Num,Den,Res; Num = 98765432; Den = 1234567; Res = Num/Den; //Display Res;
Obviously, that was a typo error, I meant 4 bytes as indicated by long int (just outside the bracket) in that line.
So your "rest of the world ..." comment was uncalled for.
The purpose of my effort is not converting characters to integers etc. but find an C code based method that can compute the ratio of two, 4 BYTE WIDE integers accurately, so that it can be automated and compared with the hardware version.
Perhaps, someone else, more helpful will try to answer the question that I asked.