Skip to content
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

"For logical right shifts operands must have at ..." #250

Closed
andreubotella opened this issue Jan 4, 2021 · 4 comments
Closed

"For logical right shifts operands must have at ..." #250

andreubotella opened this issue Jan 4, 2021 · 4 comments

Comments

@andreubotella
Copy link
Member

For logical right shifts operands must have at least twenty-one bits precision.

Shouldn't this be for left shifts? After all, the result of a logical right shift will never have more bits than the larger of its operands.

@annevk
Copy link
Member

annevk commented Jan 4, 2021

Hmm, see https://lists.w3.org/Archives/Public/www-international/2014JulSep/0027.html and replies. That might have been wrong though.

@andreubotella
Copy link
Member Author

andreubotella commented Jan 4, 2021

I actually misread that sentence as talking about the result of right shifts, rather than to the operands, which is why I thought it must be referring to left shifts. But although that message is indeed right in that bit shifts do depend on the size of the input, that only makes a difference for logical right shifts of negative numbers:

// Arithmetic right shifts
8 (i8) >> 1 = 4
8 (i16) >> 1 = 4
8 (i32) >> 1 = 4
-8 (i8) >> 1 = -4
-8 (i16) >> 1 = -4
-8 (i32) >> 1 = -4

// Logical right shifts
8 (i8) >>> 1 = 4
8 (i16) >>> 1 = 4
8 (i32) >>> 1 = 4
-8 (i8) >>> 1 = 124
-8 (i16) >>> 1 = 32764
-8 (i32) >>> 1 = 2147483644

And since the only right shifts in the standard have code points or code units as their input, they must be positive.

@annevk
Copy link
Member

annevk commented Jan 4, 2021

Okay, I would be fine dropping that sentence. I've been kinda hoping we can remove the majority of that section once whatwg/infra#87 is sorted.

@andreubotella
Copy link
Member Author

Closing this in the meantime, then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants