[Python-ideas] Floating point "closeness" Proposal Outline
Chris Barker
chris.barker at noaa.gov
Tue Jan 20 18:23:57 CET 2015
On Tue, Jan 20, 2015 at 2:58 AM, Neil Girdhar <mistersheik at gmail.com> wrote:
> I'm not against this. What I meant by invention was that it appears that
> no one defines relative error this way that I could see, which is why I
> suggested you collect some examples.
>
Did you look at the Boost docs? That's pretty much what they do, and it was
apparently derived from Kahan -- can't get a better pedigree than that ;-).
To some extent, whether it's symmetric or not depends on what you name it.
to me, at least "is_close" implies symmetry -- a is close to be , but b is
not close to a? pretty weird. but if you call it is_close_to, then I could
see that a is close to be, but b may not be close to a (though that still
seems pretty odd). ANyone got a better name?
Again, I'm pretty sure that the most common use cases (and the one where
folks are likely to use a stdlib function, rather than write their own) are
where the tolerance is approximate anyway -- i.e. ten decimal digits or so
(or 1e-10) -- these distinctions are irrelevant in that case, but the
symmetric versions may make for fewer surprises.
The mathworld article, numpy, and wikipedia all choose the asymmetric
> relative error, which is what I prefer as well.
>
See, for example:
>>
>> http://mathworld.wolfram.com/AbsoluteError.html
>> http://mathworld.wolfram.com/RelativeError.html
>
>
thanks for the links.
I think I'm sold on the relative error as it's normally defined, but I'd
>> rather we see what all of the other packages have done and why. I don't
>> think the default should be symmetrical since to me the asymmetrical case
>> seems more common.
>>
>
> How about:
>
> relative_error(true_value, approximate_value, absolute_tolerance=...,
> relative_tolerance=..., tolerance_relative_to=None)
>
Interesting -- numpy, for instance puts the "true value" (the one used to
scale) second in the parameter list... one reason that I like symmetric.
But using clear names like that does make it more clear that it isn't
symmetric.
> if tolerance_relative_to is None, replace it with true_value (or min(true,
> approx) if we go with the symmetrical definition).
>
hmm -- I'm a bit wary of too many options, but if we can't decide on the
"best" way, then that may be the way to go -- as long as the defaults are
reasonable.
[1] I know just enough to know how much I don't know.
>
>
me too -- I _barely_ passed a class with Kahan, which really did teach me
far more about what I don't know than anything else!
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150120/2ba7db71/attachment-0001.html>
More information about the Python-ideas
mailing list