operator ~/ method

Int64 operator ~/(
  1. Int64 other
)

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

Implementation

Int64 operator ~/(Int64 other) {
  if (other.isZero) throw IntegerError.divisionByZero;
  if (this == Int64.min && other == Int64.minusOne) return Int64.min;
  final negResult = isNegative != other.isNegative;
  // Negating Int64.min wraps back to its own bit pattern, which Uint64
  // correctly reads as 2^63 — exactly the right magnitude — so no
  // special-casing is needed here beyond the min/-1 guard above.
  final aMag = isNegative ? (-this)._bits : _bits;
  final bMag = other.isNegative ? (-other)._bits : other._bits;
  final q = aMag ~/ bMag;
  final result = Int64._(q);
  return negResult ? -result : result;
}