operator * method

Uint32 operator *(
  1. Uint32 other
)

Multiply, keeping only the low 32 bits (wrapping). Two 32-bit magnitudes multiplied directly can reach ~2^64 — unsafe as a double on web — so this decomposes into 16-bit limbs first, the same way Uint64.operator* and Int32.operator* do.

Implementation

Uint32 operator *(Uint32 other) {
  final a = _value, b = other._value;
  final aLo = a & _mask16, aHi = (a >>> 16) & _mask16;
  final bLo = b & _mask16, bHi = (b >>> 16) & _mask16;
  final lo = aLo * bLo; // < 2^32, safe
  final cross =
      (aLo * bHi + aHi * bLo) & _mask16; // terms < 2^32, sum < 2^33, safe
  final result = (lo + (cross << 16)) & _mask32; // both terms < 2^32, safe
  return Uint32._(result);
}