Float precision and float equality
dbd
dbd at ieee.org
Sun Dec 6 14:23:34 EST 2009
On Dec 6, 1:12 am, Raymond Hettinger <pyt... at rcn.com> wrote:
> On Dec 5, 11:42 pm, Tim Roberts <t... at probo.com> wrote:
>
> > Raymond Hettinger <pyt... at rcn.com> wrote:
>
> > > if not round(x - y, 6): ...
>
> > That's a dangerous suggestion. It only works if x and y happen to be
> > roughly in the range of integers.
.>
.> Right. Using abs(x-y) < eps is the way to go.
.>
.> Raymond
This only works when abs(x) and abs(y) are larger that eps, but not
too much larger.
Mark's suggestion is longer, but it works. The downside is it requires
you to think about the scale and accuracy of your application.
Dale B. Dalrymple
More information about the Python-list
mailing list