subChecked method

Int128 subChecked(
  1. Int128 other
)

-other wraps back to Int128.min itself when other == Int128.min (no positive counterpart in two's complement), so that case can't go through addChecked(-other) like every other value can. this - Int128.min only fits the signed range when this is negative, in which case the plain wrapping subtract is already exact.

Implementation

Int128 subChecked(Int128 other) {
  if (other == Int128.min) {
    if (!isNegative) throw IntegerError.overflow;
    return this - other;
  }
  return addChecked(-other);
}