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;