Hi guys,
does anyone know how to lose the small noise getting added to float numbers?
here is the code:
if you punch the numbers on your calculator, the answer is 80 which is correct.Code:typedef unsigned long u32;
int main()
{
float width,left;
float temp1, temp2;
u32 x;
temp1 = 640.0;
temp2 = 800.0;
width = (temp1 / temp2);
left = -(width / 2);
x = (left + 0.5f) * 800;
printf("width = %f\n",width);
printf("left = %f\n",left);
printf("x = %d\n", x);
return 0;
}
This piece of code however, shows 79.
This is because the var "width" contains very small noise after the first division. It prints out 0.8 but the actual value is 0.800000012.
Is there any way to get rid of the 12 at the end?