Skip to content

fix(tdigest): return max when the last centroid has weight 2 - #188

Open
jaideeppyne wants to merge 1 commit into
apache:mainfrom
jaideeppyne:fix/tdigest-last-weight-two
Open

jaideeppyne wants to merge 1 commit into
apache:mainfrom
jaideeppyne:fix/tdigest-last-weight-two

Conversation

@jaideeppyne

Copy link
Copy Markdown
Contributor

Quantile's right tail divides by lastWeight/2 - 1. That denominator is zero when the last centroid weighs 2, and the only rank that reaches the branch (one unit of weight below the total) has a zero numerator as well, so the result is NaN.

Java and Rust already return the stored maximum in this case. This does the same.

The rank weight is also rounded before it is subtracted from the total. On arm64 the compiler otherwise fuses that multiply and subtract, skips the right tail, and returns a value past the maximum (40 for a sketch whose maximum is 20).

Tests: go test ./tdigest/. The new case builds centroids of weight 10 and 2 and checks Quantile(11/12) is the maximum.

The right-tail division is 0/0 for that weight. Round the rank weight
before subtracting it so arm64 does not fuse the multiply and skip the tail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant