Int64 constructor
Int64(
- int value
Builds from a plain Dart int (positive or negative). value must
itself be a normal, double-safe Dart int (true for any literal or
value that didn't already come from a wider fixed-width type) —
i.e. |value| <= 2^53, so splitting it into hi/lo limbs with plain
arithmetic operators never forms an intermediate exceeding the
JS double-precision safe integer boundary.
No BigInt involved: non-negative values are split directly into
limbs; negative values split the magnitude into limbs first, then
two's-complement-negate using Uint64's existing web-safe ~ / +.
Implementation
factory Int64(int value) {
if (value >= 0) {
final hi = value ~/ 0x100000000;
final lo = value % 0x100000000;
return Int64._(Uint64.unsafe(hi, lo));
}
final mag = -value; // safe: |value| <= 2^53, so negation can't overflow
final hi = mag ~/ 0x100000000;
final lo = mag % 0x100000000;
final magBits = Uint64.unsafe(hi, lo);
return Int64._((~magBits) + Uint64.one);
}