int.parse has limited precision, contradicting docs

For dart 2,

> dart --version
Dart VM version: (google3) on "linux_x64"

the following



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;



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




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.

Author: Fantashit

1 thought on “int.parse has limited precision, contradicting docs

Comments are closed.