rangeDouble function
Returns doubles from start (inclusive) toward end (exclusive) in
increments of step. A negative step counts down; the result is empty
when the range cannot advance toward end.
Example:
rangeDouble(0, 1, 0.5); // [0.0, 0.5]
Audited: 2026-06-12 11:26 EDT
Implementation
List<double> rangeDouble(double start, double end, double step) {
final List<double> out = <double>[];
// A zero step cannot advance — guard before dividing (the old accumulating
// loop would spin forever). Compute each element as start + i*step rather than
// repeatedly adding, so floating-point error does not drift the endpoint in or
// out of the range.
if (step == 0) return out;
final int n = ((end - start) / step).ceil();
for (int i = 0; i < n; i++) {
out.add(start + i * step);
}
return out;
}