[Proposal]: Unsigned right shift operator
- Dominant language
- C#
- Stars
- 12.7k
- Forks
- 1.1k
- Avg merge
- 11h 1m
- Merged PRs (30d)
- 3
Description
# Unsigned right shift operator
* [x] Proposed
* [ ] Prototype: Not Started
* [ ] Implementation: Not Started
* [ ] Specification: Not Started
Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/unsigned-right-shift-operator.md
## Summary
[summary]: #summary
An unsigned right shift operator will be supported by C# as a built-in operator (for primitive integral types) and as a user-defined operator.
## Motivation
[motivation]: #motivation
When working with signed integral value, it is not uncommon that you need to shift bits right without replicating the high order bit on each shift. While this can be achieved for primitive integral types with a regular shift operator, a cast to an unsigned type before the shift operation and a cast back after it is required. Within the context of the generic math interfaces the libraries are planning to expose, this is potentially more problematic as the type might not necessary have an unsigned counterpart defined or known upfront by the generic math code, yet an algorithm might rely on ability to perform an unsigned right shift operation.
## Detailed design
[design]: #detailed-design
There are some considerations around what the operator could be and the initial suggestion is ```>>>```, to match other languages. It is suggested that ```>>>``` be explicitly an unsigned right shift and ```>>``` would continue being just “right shift” with no strict definition. For primitive unsigned integral types ```>>>``` will be allowed, but will be equivalent to ```>>```.
## Drawbacks
[drawbacks]: #drawbacks
## Alternatives
[alternatives]: #alternatives
## Unresolved questions
[unresolved]: #unresolved-questions
## Design meetings
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.