Float precision and float equality
r0g
aioe.org at technicalbloke.com
Sun Dec 6 15:52:05 EST 2009
dbd wrote:
> 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.
Okay, I'm confused now... I thought them being larger was entirely the
point. At what point can they become too large? Isn't eps entirely
arbitrary anyway?
>
> Mark's suggestion is longer, but it works. The downside is it requires
> you to think about the scale and accuracy of your application.
>
Shouldn't one be doing that in any case??
Roger.
More information about the Python-list
mailing list