Hi guys,
Thank you, both of you for your answers.
@iMalc: I actually did find this paper. But I guess I was just too intimidated by the size of it and hoped I would get a simpler answer here... Sorry bout that . I ll try to plough my way through it again though.
While I do that, I noticed something that I wanted to run past everyone. I was wrong when I said that rounding off the floats didnt work and everything still printed out 6 digits. Turns out some of the numbers do get rounded off.. But some of them don't.
Code:
# include <stdio.h>
# include <math.h>
int main()
{
float num1;
num1 = 16.822599; /* or 17.320499, 45.519199, 75.179802 */
/*32.324577 on the other hand gets rounded off as expected */
printf("Num1=%f\n",num1);
num1 = (float)( (int)(num1*10000 + 0.5) )/ 10000;
printf("Num1=%f\n",num1);
return (0);
}
I ve posted the snippet of test code that I used.. U ll see that with any of the numbers that I ve used, (alternative numbers in comments) the number doesn't get rounded off to 4 digits. But most numbers with 6 decimal places do get rounded off though..
I guess that once I ve read through the literature, I ll see that all of these numbers have something common in their binary representation that doesn't allow them to be rounded off any more than this. Am i right?
So is there any standard method for dealing with such numbers..? Or pointers to reading material that I could go through would be great too..
thanks,
Avinash