diff --git a/CHANGELOG.md b/CHANGELOG.md index 864a1a76..b6e3588d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/bucketGenerators.js b/lib/bucketGenerators.js index ddd51dfc..a9a487c7 100644 --- a/lib/bucketGenerators.js +++ b/lib/bucketGenerators.js @@ -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; }; diff --git a/test/bucketGeneratorsTest.js b/test/bucketGeneratorsTest.js index 5f8d5860..898be657 100644 --- a/test/bucketGeneratorsTest.js +++ b/test/bucketGeneratorsTest.js @@ -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', () => {