Geometric mean calculator
The average for things that multiply — growth rates, returns, ratios. It does not multiply your numbers together, because that is what every textbook says and it returns Infinity for two hundred values of 100, whose geometric mean is obviously 100. Nothing you type here leaves your browser — it is worked out on your own device, so there is nothing to send and nothing to log.
Why the textbook formula returns Infinity
The geometric mean of n numbers is the nth root of their product:
GM = x₁ × x₂ × … × xₙ1/n
The algebra is right and the arithmetic does not survive. A product grows enormously faster than the numbers in it, and a double stops at about 1.8×10308:
| Two hundred values of 100 | product is 10400 → Infinity |
|---|---|
| Four hundred values of 0.01 | product underflows → exactly 0 |
Both answers are obvious to a person and unreachable by that formula. The fix is old and simple: the log of a product is the sum of the logs, so take logs, average them, and exponentiate. Sums do not overflow where products do.
GM = exp( ( ln x₁ + ln x₂ + … + ln xₙ ) ÷ n )
And then the sum loses digits too
Taking logs fixes the overflow and introduces a
quieter problem: adding hundreds of floating-point logs one at a time
loses the small ones. This page sums them with Neumaier compensation,
which keeps the part a plain addition throws away. Measured against
CPython's own statistics.geometric_mean, which sums with
math.fsum — a different method, so agreement means
two independent routes to the same answer:
| Two hundred 100s, product | Infinity |
|---|---|
| … logs added plainly | 99.9999999999987 |
| … logs added with compensation | 100.00000000000004 |
| Python's answer | 100.00000000000004 |
And [2, 8] gives 4 under every one of those methods. Two values, a tidy product, no overflow and nothing to compensate for — which is why the example in the textbook cannot tell a sound implementation from a broken one.
When to use it instead of the ordinary average
Use the geometric mean when your numbers multiply rather than add. Three years of growth at 5%, 12% and −3% compound; their arithmetic mean answers a question nobody asked, and their geometric mean is the single rate that would have produced the same total.
The geometric mean is never larger than the arithmetic mean, and the two are equal only when every value is identical. This page shows both, so the gap between them is visible.
Every value has to be positive. One negative makes the product negative, and an even root of a negative has no real value — so the answer would exist for an odd count of values and vanish for an even one. A single zero takes the whole mean to zero. Neither is a limitation of this page; both are properties of the thing itself, and it says which one it met.
Where to go next
- Percentage difference calculator
- Weighted average calculator
- Proportion calculator
- Mean, median and standard deviation — the ordinary averages, and the spread.
- Weighted average
- Every tool on the site