Representing $100001$ in floating point system

210 Views Asked by At

There's an example in my textbook about cancellation error that I'm not totally getting. It says that with a $5$ digit decimal arithmetic, $100001$ cannot be represented.

I think that's because when you try to represent it you get $1*10^5$, which is $100000$. However it goes on to say that when $100001$ is represented in this floating point system (when it's either chopped or rounded) it comes to $100000$.

If what I said above is correct, does $100001$ go to $100000$ because of the fact that it can only be represented like $1*10^5$?

If I'm completely off the mark, clarification would be great.

3

There are 3 best solutions below

2
On BEST ANSWER

Yes, you only have five decimal digits available. $100001=1.00001*10^5$ but I have six digits in the mantissa. Clearly it is closer to go to $1.0000$ than to $1.0001$, so that is what we will do. So the numbers around here that can be represented are $99998, 99999, 100000, 100010, 100020,$ etc.

0
On

I think the point is about the precision of the number that can be stored, not so much the exponent. In other words you cannot store $1.00001*10^5$ because it cannot store five decimal places of precision. Equally it would not be able to store $1.00001*10^{15}$ or $1.00001*10^{-5}$.

5
On

That is correct. You have what is called type overflow. Want to be amused? If you have a C compiler run this program

#include<stdio.h>
int main(void)
{
    int x = 1;
    while (x > 0)
    {
        x = x + 1;
    }
    printf("x = %d\n", x);
}

It's educational. This is in integer-world so it's simpler than floating point numbers, but these have an analogous problem: loss of precision. I recommend Forman Acton's Real Computing Made Real for a discussion of this issue.