Skip to content

Commit 8a7cb87

Browse files
committed
fix: correct Linspace endpoint inclusion and update related tests
1 parent 94e1f8c commit 8a7cb87

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@
150150
and ternary compilation behavior. No behavioral change — the rules
151151
were already implemented; only the description was incomplete.
152152

153+
#### Fixed
154+
155+
- **`Linspace` endpoint inclusion**`Linspace(a, b, n)` now produces `n`
156+
points evenly spanning `[a, b]` inclusive of both endpoints (matching NumPy,
157+
Julia, and MATLAB convention). Previously the divisor was `n` instead of
158+
`n - 1`, so the last sample fell short of `b` (e.g. `Linspace(0, 1, 5)`
159+
yielded `0, 0.2, 0.4, 0.6, 0.8` instead of `0, 0.25, 0.5, 0.75, 1`). The
160+
`at`, `iterator`, and `contains` handlers are all corrected. `Linspace(a, b,
161+
1)` is the degenerate case and returns just `a`. The `contains` check is
162+
also now tolerance-based (was an exact `%` test that failed for typical
163+
floating-point values).
164+
153165
#### Known issues
154166

155167
- **JS `Loop` compile produces `undefined`** — the imperative `for`-loop IIFE

test/compute-engine/collections.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,17 @@ describe('DROP 2', () => {
251251
expect(evaluate(['Drop', linspace, 2])).toMatchInlineSnapshot(`
252252
[
253253
"List",
254-
4.202247191011236,
255-
5.3033707865168545,
256-
6.404494382022472,
257-
7.50561797752809,
258-
8.606741573033709,
254+
4.227272727272727,
255+
5.340909090909091,
256+
6.454545454545454,
257+
7.568181818181818,
258+
8.681818181818182,
259259
"ContinuationPlaceholder",
260-
94.49438202247191,
261-
95.59550561797752,
262-
96.69662921348315,
263-
97.79775280898876,
264-
98.89887640449439
260+
95.54545454545455,
261+
96.6590909090909,
262+
97.77272727272727,
263+
98.88636363636364,
264+
100
265265
]
266266
`));
267267

@@ -342,7 +342,7 @@ describe('SLICE (2,3)', () => {
342342

343343
test('linspace', () =>
344344
expect(evaluate(['Slice', linspace, 2, 3])).toMatchInlineSnapshot(
345-
`["List", 3.101123595505618, 4.202247191011236]`
345+
`["List", 3.1136363636363633, 4.227272727272727]`
346346
));
347347

348348
test('tuple', () =>

0 commit comments

Comments
 (0)