DoubleRange constructor

DoubleRange(
  1. double start,
  2. double stop, [
  3. double step = 1
])

Returns an iterable of integers from start inclusive to stop inclusive with step.

Examples: print(DoubleRange(0, 5)); // (0.0, 1.0, 2.0, 3.0, 4.0, 5.0) print(DoubleRange(0, 5, 0.5)); // (0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0) print(DoubleRange(5, -5)); // (5.0, 4.0, 3.0, 2.0, 1.0, 0.0, -1.0, -2.0, -3.0, -4.0, -5.0)

Implementation

factory DoubleRange(double start, double stop, [double step = 1]) {
  if (step == 0) {
    throw ArgumentError.value(step, 'step', 'cannot be 0');
  }

  if (stop < start) {
    if (!step.isNegative) {
      step = -step;
    }
  } else {
    if (step.isNegative) {
      step = -step;
    }
  }
  return DoubleRange._(start, stop, step);
}