Uint64.from constructor

Uint64.from(
  1. int value
)

Builds from a plain Dart int, accepting negative values by taking their two's-complement bit pattern (masked to 64 bits) instead of throwing like Uint64.new does — e.g. Uint64.from(-1) == Uint64.max. value must itself be a normal double-safe Dart int (|value| <= 2^53); mirrors the negation trick Int64.new already uses.

Implementation

factory Uint64.from(int value) {
  final isNeg = value < 0;
  final mag = isNeg ? -value : value; // safe: |value| <= 2^53
  final magBits = Uint64.unsafe(mag ~/ 0x100000000, mag % 0x100000000);
  return isNeg ? (~magBits) + Uint64.one : magBits;
}