subChecked method

Int32 subChecked(
  1. Int32 other
)

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

Implementation

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