Skip to content

linspace

linspace(start, stop, count): number[]

Defined in: linspace.ts:33

Evenly spaced samples across a closed interval, endpoints included.

The sequence form of lerp: sample index is lerp(start, stop, index / (count - 1)). Interpolating rather than accumulating start + index * step is what keeps the last sample exactly stop — an accumulated step drifts, and a caller sampling a function that is singular at one endpoint gets a point just inside or just outside the domain depending on the rounding.

Distinct from @ac-kit/core’s range, which is step-based with an exclusive bound. Reach for this one when the sample count is what matters and both endpoints must be hit; reach for range when the stride is what matters.

O(count) time and O(count) memory — the whole sequence is materialised.

number

The first sample.

number

The last sample.

number

How many samples to produce. A count of 1 yields [start], since no interval can be divided into zero segments.

number[]

count samples ascending from start to stop.

linspace(0, 1, 5); // [0, 0.25, 0.5, 0.75, 1]
linspace(0, 1, 5).at(-1) === 1; // true — the endpoint is exact
```;
## Throws
If `count` is not a positive safe integer, or if either
endpoint is not finite.