operator ~/ method

Int32 operator ~/(
  1. Int32 other
)

Truncating division (toward zero), like Rust's / or C's /. Int32.min ~/ Int32.minusOne wraps back to Int32.min (the one case where the mathematical quotient doesn't fit).

Implementation

Int32 operator ~/(Int32 other) {
  if (other.isZero) throw IntegerError.overflow;
  if (this == Int32.min && other == Int32.minusOne) return Int32.min;
  return Int32(toInt() ~/ other.toInt()); // magnitudes <= 2^31, safe
}