Numbers and Math
BigInt Arithmetic
BigInt is Dart's arbitrary-precision integer. Build values with BigInt.parse(text) for decimal text or BigInt.from(int) to widen an ordinary int. The usual operators +, -, *, ~/ stay exact on BigInt operands no matter how large, so they handle magnitudes the 64-bit int cannot represent. BigInt.toString() is the full decimal expansion.
Program
Play the program to parse a 21-digit BigInt, double it, integer-divide it, and count its decimal digits.
bigint.dart
void main() {
var big = BigInt.parse('100000000000000000000');
var two = BigInt.from(2);
var doubled = big * two;
var halved = big ~/ two;
var digits = big.toString().length;
print('$doubled $halved digits=$digits');
}
BigInt.parse
`BigInt.parse(decimal)` reads arbitrary-precision integers from text. There is no overflow on the parsed value.
BigInt.from
`BigInt.from(int)` widens an ordinary `int` to a `BigInt` so it can mix with other `BigInt` operands.
exact arithmetic
`+`, `*`, `~/` on `BigInt` operands stay exact regardless of magnitude; the result is another `BigInt`.