Quant Memo
Coding/●●●●●

Geometric mean without overflowing the product

The geometric mean of nn positive numbers is the nn-th root of their product, (ixi)1/n\left(\prod_i x_i\right)^{1/n}. It is the right average for growth rates and multiplicative returns. But the obvious code multiplies everything first, and a product of even a few dozen mid-sized numbers overflows a 64-bit integer or a double's range almost immediately.

Compute the geometric mean of a list of positive numbers without ever forming the full product.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions