Reputation: 511538
I'm trying to create a BigInt in Dart just to learn about BigInt.
I tried this
var x = 237462836487263478235472364782364827648632784628364;
But that gives an error because the compiler thinks its an int but greater than 64 bits.
Then I saw this answer, so I tried this:
var x = BigInt.from(237462836487263478235472364782364827648632784628364);
That still gives the same error:
The integer literal 237462836487263478235472364782364827648632784628364 can't be represented in 64 bits.
Try using the BigInt class if you need an integer larger than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808.
I thought I was using the BigInt class.
Upvotes: 6
Views: 2481
Reputation: 511538
Looking at the source code, it turns out the way to create a BigInt
from a number literal is to parse it from a string:
final x = BigInt.parse('237462836487263478235472364782364827648632784628364');
final y = BigInt.from(1);
final z = x + y;
// 237462836487263478235472364782364827648632784628365
Upvotes: 9