divide method

IntervalDomain divide(
  1. IntervalDomain other
)

Integer division of two intervals.

Returns top if the divisor interval contains zero (division by zero possible).

Implementation

IntervalDomain divide(IntervalDomain other) {
  if (isBottom || other.isBottom) return bottomValue;

  // If either operand is top, result is top
  if (isTop || other.isTop) return topValue;

  // Division by interval containing zero is undefined
  if (other.containsValue(0)) {
    return topValue;
  }

  // Handle infinity cases conservatively
  if (min == null || max == null || other.min == null || other.max == null) {
    return _divideWithInfinity(other);
  }

  // All bounds are finite and divisor doesn't contain zero
  // Compute all corner quotients using truncating division
  final quotients = <int>[
    min! ~/ other.min!,
    min! ~/ other.max!,
    max! ~/ other.min!,
    max! ~/ other.max!,
  ];

  return IntervalDomain(
    quotients.reduce(math.min),
    quotients.reduce(math.max),
  );
}