-
Notifications
You must be signed in to change notification settings - Fork 867
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
feat: support bitwise
shift left/right
#4148
Conversation
bitwise
shift left/right
@@ -143,6 +177,24 @@ mod tests { | |||
Ok(()) | |||
} | |||
|
|||
#[test] |
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 it worth adding a test of what happens if you shift by more than the number of 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.
I add a test for it. It should be 0
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.
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.
This makes sense, as wrapping_shr
would shift the position would be the remainder of the type. So wrapping_shr(3_i32, 32) == 3
and wrapping_shr(3_i32, 33) == 1
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.
Shift operations (<<, >>) on a value of width N can be passed a shift value >= N. It is unclear what behaviour should result from this, so the shift value is unconditionally masked to be modulo N to ensure that the argument is always in range.
I found the reason here https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md
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.
Thank you @Weijun-H -- I can't wait to use this to simplify datafusion
use arrow_schema::ArrowError; | ||
use num::traits::{WrappingShl, WrappingShr}; |
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.
this is great -- when I looked into doing this in DataFusion I noticed these traits weren't in std
-- 100% for finding them in num
Which issue does this PR close?
Closes #2741
Rationale for this change
Support
bitwise_shift_right
andbitwise_shift_left
. And use 'as_usize' to ignore truncation.What changes are included in this PR?
Are there any user-facing changes?