Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,19 @@ static double exponentiallyScaledToDoubleValue(long index, int scale) {
*/
public static double getPointOfLeastRelativeError(long bucketIndex, int scale) {
checkIndexAndScaleBounds(bucketIndex, scale);
double upperBound = getUpperBucketBoundary(bucketIndex, scale);
double histogramBase = Math.pow(2, Math.scalb(1, -scale));
return 2 / (histogramBase + 1) * upperBound;
if (Double.isFinite(histogramBase)) {
double upperBound = getUpperBucketBoundary(bucketIndex, scale);
return 2 / (histogramBase + 1) * upperBound;
} else {
if (bucketIndex >= 0) {
// the bucket is (1, +inf), approximate point of least error as inf
return Double.POSITIVE_INFINITY;
} else {
// the bucket is (1/(Inf), 1), approximate point of least error as 0
return 0;
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public void testExtremeValueIndexing() {
}
}

public void testPointOfLeastErrorAtInfinity() {
assertThat(getPointOfLeastRelativeError(0, MIN_SCALE), equalTo(Double.POSITIVE_INFINITY));
assertThat(getPointOfLeastRelativeError(-1, MIN_SCALE), equalTo(0.0));
assertThat(getPointOfLeastRelativeError(10, MIN_SCALE + 2), equalTo(Double.POSITIVE_INFINITY));
}

public void testRandomValueIndexing() {
for (int i = 0; i < 100_000; i++) {
// generate values in the range 10^-100 to 10^100
Expand Down