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 reed
Recipients mark.dickinson, reed, rhettinger, steven.daprano, taleinat, xtreak
Date 2020-01-05.20:37:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578256653.54.0.488351288618.issue39218@roundup.psfhosted.org>
In-reply-to
Content
Thank you all for the comments! Either using (x-c)*(x-c), or removing the assertion and changing the final line to `return (U, total)`, seem reasonable. I slightly prefer the latter case, due to Mark's comments about x*x being faster and simpler than x**2. But I am not an expert on this.

> I am inclined to have the stdev of float32 return a float32 is possible. What do you think?

Agreed.

> OTOH, (x-c)*(x-c) repeats the subtraction unnecessarily, but perhaps assignment expressions could rescue us?

Yeah, we should avoid repeating the subtraction. Another method of doing so is to define a square function. For example:

    def square(y):
        return y*y
    sum(square(x-c) for x in data)

> Would that also imply intermediate calculations being performed only with float32, or would intermediate calculations be performed with a more precise type?

Currently, statistics.py computes sums in infinite precision (https://github.com/python/cpython/blob/422ed16fb846eec0b5b2a4eb3a978c9862615665/Lib/statistics.py#L123) for any type. The multiplications (and exponents if we go that route) would still be float32.
History
Date User Action Args
2020-01-05 20:37:33reedsetrecipients: + reed, rhettinger, mark.dickinson, taleinat, steven.daprano, xtreak
2020-01-05 20:37:33reedsetmessageid: <1578256653.54.0.488351288618.issue39218@roundup.psfhosted.org>
2020-01-05 20:37:33reedlinkissue39218 messages
2020-01-05 20:37:33reedcreate