Question about ints in Dart (bit size)

69 views
Skip to first unread message

Si Robertson

unread,
Sep 1, 2014, 4:01:37 AM9/1/14
to mi...@dartlang.org
Hi guys,

What is the bit size of ints in Dart?

The reason I ask is because of this ...

  int a = 0xFFFFFFFF;
  int b = 255 << 24 | 255 << 16 | 255 << 8 | 255;

  print(a); // 4294967295
  print(b); // 4294967295

  print(a.runtimeType); // int

Normally I would expect those values to wrap around to -1 (32-bit signed integer) which is why the behaviour here caught me off guard. Is the Dart VM converting ints to doubles behind the scenes or is something else going on here?

Thanks :)

FYI, the code is running in the Dart VM.

Günter Zöchbauer

unread,
Sep 1, 2014, 4:18:22 AM9/1/14
to mi...@dartlang.org

Si Robertson

unread,
Sep 1, 2014, 4:21:20 AM9/1/14
to mi...@dartlang.org
Awesome. Thanks, Günter :)

Cogman

unread,
Sep 1, 2014, 11:14:53 AM9/1/14
to mi...@dartlang.org
It is mentioned in Gunter's link but bears repeating.  Dart's ints behave different in the dartvm vs after being compiled by dart2js.  dart2js doesn't do anything to solve the fact that all javascript numerics are doubles.  As a result, things get weird when you talk about abs(numbers) > 2^53


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Reply all
Reply to author
Forward
0 new messages