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
Expand docs for bitshift operators #14790
Conversation
@@ -2082,7 +2082,11 @@ kron | |||
""" | |||
>>(x, n) | |||
|
|||
Right bit shift operator, preserving the sign of `x`. | |||
Signed right bit shift operator, `x >> n`. The result is `x` shifted right by `n` bits, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>
is not always signed; it is signed for signed types, and unsigned for unsigned types.
That is, unsigned types always shift in zeros from the left.
The result is not undefined for negative n
; there is generally very little undefined behaviour in Julia. Instead, n
is reinterpreted as unsigned number. (This could/should/will change, leading to an error instead in this case.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point: I hadn't noticed that the code in intrinsics.cpp
used an unsigned comparison. However, that's not quite true: big(1) << -1
returns an error, not big(1) << unsigned(-1)
(which would be huge).
209dd34
to
582343d
Compare
LGTM. |
@@ -6225,7 +6227,8 @@ nextind | |||
""" | |||
>>>(x, n) | |||
|
|||
Unsigned right bit shift operator. | |||
Unsigned right bit shift operator, `x >>> n`. The result is `x` shifted right by `n` bits, | |||
where `n >= 0`, filling with `0`s. This is equivalent to `(unsigned(x) >> n) % T`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where did T come from?
please run genstdlib here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch.
Actually, should these be moved inline? If so, would they be better in int.jl
or operators.jl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may as well move them inline, yeah. I think operators.jl has the most general signature, but don't think it matters too much
582343d
to
40f7ebc
Compare
I feel like an example may help here, e.g.
but that may be a little too verbose? |
Good idea. The only problem is that the exact output will depend on the exact type of |
40f7ebc
to
9adcec9
Compare
Could perhaps make it shorter and platform independent by specifying the int type: julia> Int8(3) << 2
12
julia> bits(Int8(3))
"00000011"
julia> bits(Int8(12))
"00001100" |
@KristofferC that's a good idea, makes it much more readable. |
d4bb9d8
to
734d737
Compare
Unsigned right bit shift operator, `x >>> n`. The result is `x` shifted right by `n` bits, | ||
where `n >= 0`, filling with `0`s. | ||
|
||
`BigInt`s are treated as if having infinite size, so no filling is required and this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: I wonder if the example should go before the bigint note?
This is a big improvement, looks great!
This is a good change. I like it if functions contain pointers to other, related functions. You could add a "See also: |
734d737
to
7e070a4
Compare
Expand docs for bitshift operators
""" | ||
Base.(:(>>)) | ||
fieldoffsets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrectly resolved conflict here? fieldoffsets
was recently deprecated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I figured that was intentional. PR to fix below/soon.
This was accidentally added in JuliaLang#14790.
This was accidentally added in JuliaLang#14790.
No description provided.