step

infix fun ClosedRange<Double>.step(step: Double): @Unmodifiable DoubleList

Returns a read-only DoubleList representing this ClosedRange of Double values stepped by the specified step.

The returned list is virtual: elements are not stored in memory, but computed on demand when accessed by index. This provides O(1) memory usage and supports random access.

The size of the list is calculated based on the range and the step, with a small epsilon (EPSILON_D) to account for floating-point inaccuracies.

Example:

val list = (0.0..1.0).step(0.25)
println(list) // [0.0, 0.25, 0.5, 0.75, 1.0]
println(list[2]) // 0.5

Notes:

Return

a read-only DoubleList representing the stepped range.

Parameters

step

the step size between consecutive elements, must be > 0.

Throws

if step is not positive, the range contains non-finite values, or the stepped range would contain more than Int.MAX_VALUE elements.


infix fun ClosedRange<Float>.step(step: Float): @Unmodifiable FloatList

Returns a read-only FloatList representing this ClosedRange of Float values stepped by the specified step.

The returned list is virtual: elements are not stored in memory, but computed on demand when accessed by index. This provides O(1) memory usage and supports random access.

The size of the list is calculated based on the range and the step, with a small epsilon (EPSILON_F) to account for floating-point inaccuracies.

Example:

val list = (0f..1f).step(0.25f)
println(list) // [0.0, 0.25, 0.5, 0.75, 1.0]
println(list[2]) // 0.5

Notes:

Return

a read-only FloatList representing the stepped range.

Parameters

step

the step size between consecutive elements, must be > 0.

Throws

if step is not positive, the range contains non-finite values, or the stepped range would contain more than Int.MAX_VALUE elements.