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 mark.dickinson, steven.daprano
Date 2016-10-01.12:18:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1475324315.92.0.282609876939.issue28327@psf.upfronthosting.co.za>
In-reply-to
Content
The following calculations should all be giving the same result:

>>> import statistics
>>> statistics.geometric_mean([2, 3, 5, 7])
3.80675409583932
>>> statistics.geometric_mean([2, 3, 5, 7.0])
1.6265765616977859
>>> statistics.geometric_mean([2, 3, 5.0, 7.0])
2.4322992790977875
>>> statistics.geometric_mean([2, 3.0, 5.0, 7.0])
3.201085872943679
>>> statistics.geometric_mean([2.0, 3.0, 5.0, 7.0])
3.80675409583932

(Correct result is 3.80675409583932.)

The culprit is this line in statistics._product:

    mant, scale = 1, 0  #math.frexp(prod)  # FIXME

... and indeed, we should be starting from `prod` rather than 1 here. But simply using math.frexp has potential for failure if the accumulated integer product overflows a float.
History
Date User Action Args
2016-10-01 12:18:35mark.dickinsonsetrecipients: + mark.dickinson, steven.daprano
2016-10-01 12:18:35mark.dickinsonsetmessageid: <1475324315.92.0.282609876939.issue28327@psf.upfronthosting.co.za>
2016-10-01 12:18:35mark.dickinsonlinkissue28327 messages
2016-10-01 12:18:35mark.dickinsoncreate