Skip to content

Commit

Permalink
Avoid propagating rounding errors in linearBuckets
Browse files Browse the repository at this point in the history
  • Loading branch information
tniessen authored and zbjornson committed Sep 19, 2021
1 parent dbe0aad commit 6f1f3b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,11 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Breaking

- changed: `linearBuckets` does not propagate rounding errors anymore.

Fewer bucket bounds will be affected by rounding errors. Histogram bucket
labels may change.

### Changed

### Added
Expand Down
3 changes: 1 addition & 2 deletions lib/bucketGenerators.js
Expand Up @@ -7,8 +7,7 @@ exports.linearBuckets = (start, width, count) => {

const buckets = new Array(count);
for (let i = 0; i < count; i++) {
buckets[i] = start;
start += width;
buckets[i] = start + i * width;
}
return buckets;
};
Expand Down
5 changes: 5 additions & 0 deletions test/bucketGeneratorsTest.js
Expand Up @@ -27,6 +27,11 @@ describe('bucketGenerators', () => {
};
expect(fn).toThrowError(Error);
});

it('should not propagate rounding errors', () => {
result = linearBuckets(0.1, 0.1, 10);
expect(result[9]).toEqual(1);
});
});

describe('exponential buckets', () => {
Expand Down

0 comments on commit 6f1f3b2

Please sign in to comment.