Skip to content

Commit f5883f6

Browse files
committed
Don’t include negative zero in ticks.
1 parent 8153bcd commit f5883f6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/ticks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ export default function(start, stop, count) {
2020
ticks = new Array(n = Math.ceil(stop - start + 1));
2121
while (++i < n) ticks[i] = (start + i) * step;
2222
} else {
23+
step = -step;
2324
start = Math.floor(start * step);
2425
stop = Math.ceil(stop * step);
25-
ticks = new Array(n = Math.ceil(start - stop + 1));
26-
while (++i < n) ticks[i] = (start - i) / step;
26+
ticks = new Array(n = Math.ceil(stop - start + 1));
27+
while (++i < n) ticks[i] = (start + i) / step;
2728
}
2829

2930
if (reverse) ticks.reverse();

test/ticks-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ tape("ticks(start, stop, count) returns the empty array if count is infinity", f
3737
test.end();
3838
});
3939

40+
tape("ticks(start, stop, count) does not include negative zero", function(test) {
41+
test.equal(1 / array.ticks(-1, 0, 5).pop(), Infinity);
42+
test.end();
43+
});
44+
4045
tape("ticks(start, stop, count) returns approximately count + 1 ticks when start < stop", function(test) {
4146
test.deepEqual(array.ticks( 0, 1, 10), [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]);
4247
test.deepEqual(array.ticks( 0, 1, 9), [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]);

0 commit comments

Comments
 (0)