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. |