This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients josh.r, mark.dickinson, rhettinger, steven.daprano, tim.peters
Date 2019-02-06.20:25:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549484747.45.0.995915923308.issue35904@roundup.psfhosted.org>
In-reply-to
Content
> Are you saying that "fsum(seq) / len(seq)" is incorrect because on some
> older builds there is a rare possibility of an error of 1 unit in the last
> place?

Just to be clear, it's not that rare a possibility, and it's not restricted to older builds. I think Raymond is referring to the bug where on some machines that are still using the x87 for arithmetic, double rounding can lead to the fsum result being out (by potentially an arbitrary amount, not just 1 ulp). But even without that consideration, we'll still often be out by 1 ulp or more on typical new systems.

However, if I got my sums right (and assuming that fsum _is_ correctly rounded, and IEEE 754 arithmetic is in use, and the rounding mode hasn't been changed from its default of round-ties-to-even, and we're excluding corner cases like overflow, underflow, etc., etc.), the result of fsum(seq) / len(seq) can never be out by more than 1.5 ulps. That's better than NumPy can promise (even with its use of pairwise summation in some -- but not all -- cases), and should be good enough for almost any practical purpose.

I think I'd rather see the regular statistics.mean sacrifice the good-to-the-last-bit accuracy (and it's really not that much of a sacrifice: accurate to 1.5 ulps is a _very_ respectable compromise) than have a new function. I don't know how feasible that is, though, given all the type-handling in statistics.mean.

Bikeshedding time: the proposed fmean name seems a bit unfortunate in that it's reversing the sense of sum and fsum, where fsum is the correctly-rounded, slightly slower variant. My first assumption on seeing the name was that fmean was supposed to be to mean as fsum is to sum.
History
Date User Action Args
2019-02-06 20:25:49mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, steven.daprano, josh.r
2019-02-06 20:25:47mark.dickinsonsetmessageid: <1549484747.45.0.995915923308.issue35904@roundup.psfhosted.org>
2019-02-06 20:25:47mark.dickinsonlinkissue35904 messages
2019-02-06 20:25:47mark.dickinsoncreate