mulChecked method

U64 mulChecked(
  1. U64 other
)

Implementation

U64 mulChecked(U64 other) {
  if (value == 0 || other.value == 0) return U64(0);
  // BigInt needed to strictly verify multiplication fits cleanly without wrapping bits incorrectly.
  final bi1 = BigInt.from(value).toUnsigned(64);
  final bi2 = BigInt.from(other.value).toUnsigned(64);
  final res = bi1 * bi2;
  if (res.bitLength > 64) {
    throw StateError('U64 multiplication overflow');
  }
  return U64((value * other.value).toUnsigned(64));
}