Possible duplicate:
What is the first integer that the floating IEEE 754 cannot represent exactly?
First, itβs a matter of homework, just to make it clear right away. Of course, I'm not looking for false nutrition, maybe a little pointer to the right direction.
So, my task is to find the smallest positive integer that cannot be represented as an IEEE-754 float (32 bits). I know that equality testing for something like "5 == 5.00000000001" will fail, so I thought I would simply surpass all the numbers and experience it like this:
int main(int argc, char **argv)
{
unsigned int i;
printf("IEEE floating point rounding failure detection\n\n");
for (i = 0;; ++i)
{
float result = (float)i;
if (result != i)
break;
}
printf("The smallest integer that can not be precisely represented as IEEE-754"
" is:\n\t%d", i);
return 0;
}
. "i" " ", "i" - "0.000000002", , .
- , , ?
-------------------- ---------------
! :
!