dart-lang / dart-lang/language
Dart numbers, when compiled to JavaScript, are unsigned 32 bit
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Cf. https://github.com/dart-lang/sdk/issues/42892#issuecomment-667414031, 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.
Contributor guide
Research direction
Start with the appendix on the treatment of numbers in Dart compiled to JavaScript, and compare its current wording with the referenced Dart SDK issue comment. Done means the appendix states that bit operations treat operands as unsigned 32-bit values and includes the `.toSigned(32)` example for signed results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100