Skip to content

Dart numbers, when compiled to JavaScript, are unsigned 32 bit #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
eernstg opened this issue Aug 4, 2020 · 2 comments
Open

Dart numbers, when compiled to JavaScript, are unsigned 32 bit #1129

eernstg opened this issue Aug 4, 2020 · 2 comments
Labels
bug There is a mistake in the language specification or in an active document specification

Comments

@eernstg
Copy link
Member

eernstg commented Aug 4, 2020

Cf. dart-lang/sdk#42892 (comment), the appendix about the treatment of numbers in Dart when compiled to JavaScript needs to be updated such that it mentions that bit operations consider the operands to be unsigned 32 bit values rather than signed ones:

We chose to make all bit operations unsigned because it makes more code work
than accepting JavaScript's signed behaviour. In particular the following kinds of
code often have bugs with signed values: implementations of bit-arrays as an array
of 32-bit integers; code that packs bool or int fields into an integer; code that does
rotates by combining shifts.

If a signed result is needed it can be obtained via .toSigned(32), e.g. (-1 << 10).toSigned(32).

The current wording implies that Dart uses the JavaScript semantics.

@eernstg eernstg added bug There is a mistake in the language specification or in an active document specification labels Aug 4, 2020
@eernstg
Copy link
Member Author

eernstg commented Aug 11, 2020

Spec adjustment here.

@eernstg
Copy link
Member Author

eernstg commented Aug 11, 2020

Tests here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is a mistake in the language specification or in an active document specification
Projects
None yet
Development

No branches or pull requests

1 participant