Message277808
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. |
|
Date |
User |
Action |
Args |
2016-10-01 12:18:35 | mark.dickinson | set | recipients:
+ mark.dickinson, steven.daprano |
2016-10-01 12:18:35 | mark.dickinson | set | messageid: <1475324315.92.0.282609876939.issue28327@psf.upfronthosting.co.za> |
2016-10-01 12:18:35 | mark.dickinson | link | issue28327 messages |
2016-10-01 12:18:35 | mark.dickinson | create | |
|