operator ~/ method

Int128 operator ~/(
  1. Int128 other
)

Truncating division (toward zero). Int128.min ~/ Int128.minusOne wraps back to Int128.min (the one case where the mathematical quotient doesn't fit).

Implementation

Int128 operator ~/(Int128 other) {
  if (other.isZero) throw IntegerError.divisionByZero;
  if (this == Int128.min && other == Int128.minusOne) return Int128.min;
  final negResult = isNegative != other.isNegative;
  final aMag = isNegative ? (-this)._bits : _bits;
  final bMag = other.isNegative ? (-other)._bits : other._bits;
  final q = aMag ~/ bMag;
  final result = Int128._(q);
  return negResult ? -result : result;
}