Is there a way to know when will a floating-point computation be accurate/inaccurate without actually doing the computation?

Viewed 40

I understand that floating-point computation is inherently inaccurate due to rounding errors. But how can I understand that it is sometimes accurate, sometimes inaccurate, like the following:

In [58]: 0.2+0.2==0.4
Out[58]: True

In [59]: 0.2+0.1==0.3
Out[59]: False

I guess this has something to do with the representation of floating-point numbers. Any idea? In particular, when will this be accurate/inaccurate -- Is there a way to know that in advance, namely, without actually doing the computation itself?

0 Answers
Related