Skip to content

Add a geometric mean for numeric iterables - #307

Open
CHX606 wants to merge 1 commit into
d3:mainfrom
CHX606:feat/geometric-mean
Open

CHX606 wants to merge 1 commit into
d3:mainfrom
CHX606:feat/geometric-mean

Conversation

@CHX606

@CHX606 CHX606 commented Dec 2, 2026

Copy link
Copy Markdown

Closes #194.

Adds gmean(values[, accessor]) using D3’s existing numeric iterator. Summing logarithms avoids overflowing the product for inputs such as [2 ** 1000, 2 ** 1002].

The negative-only example in the linked notebook gives gmean([-1, -4]) === -2. Mixed signs give NaN in either order, and an empty iterable returns undefined as with mean.

Verified on Node 24 with ESLint, all four Rollup outputs, and Vitest (536 passed, one skipped). I also imported gmean through the built package entry point.

Prepared with OpenAI Codex.

@Fil

Fil commented Dec 3, 2026

Copy link
Copy Markdown
Member

the prototype in https://observablehq.com/@fil/d3-gmdn is 10x faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

geometric mean?

2 participants