For dart 2,
> dart --version
Dart VM version: 2.0.0-dev.52.0+google3-v2.0.0.dev.52.0 (google3) on "linux_x64"
the following
int.parse('230423094239402322234');
yields
FormatException: Invalid radix-10 number
because apparently int
has bounded precision in dart 2. More evidence of its bounded precision:
var n = 2304230942394023222;
for (var i = 0; i < 4; i++) {
n *= 2;
print(n);
}
yields
4608461884788046444
9216923769576092888
-12896534557365840
-25793069114731680
Notice how it overflowed and became negative. In fact, it seems like the largest integer dart 2 can parse is 2^63-1 = 9223372036854775807.
The dart 2 docs for int
here say
int class
An arbitrarily large integer.
So the docs are wrong.
For dart 1,
> dart --version
Dart VM version: 1.24.3 (Wed Dec 13 23:26:59 2017) on "macos_x64"
the following
int.parse('2304230942394023222349034583405983450384509');
yields
2304230942394023222349034583405983450384509
which makes me believe that for dart 1, int
is an arbitrarily large integer, but for dart 2, it’s basically Int64
.
In the “differences” section of the dart 2 welcome page, you’d think that this might be mentioned… changing the fundamental semantics of one of the most important types in the language.
Assuming this change was intentional, can it be added to the differences section, with an explanation, and worked into the API docs? So far, the only hint I found about this change is a vague comment by rnystrom here in 2015 saying that he doesn’t think arbitrary precision ints are worth it.
Seems some docs need to be updated. The CHANGELOG.md mentions it though
(last link in )