This is an automated email from the ASF dual-hosted git repository.
viirya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new abd80ae014 Support references in i256 arithmetic ops (#4692)
abd80ae014 is described below
commit abd80ae014e1927fa60f51a159b17ac3d7500fac
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Tue Aug 15 00:02:52 2023 -0700
Support references in i256 arithmetic ops (#4692)
* Support references in i256 arithmetic ops
* Fix clippy
* For review
---
arrow-buffer/src/bigint/mod.rs | 77 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/arrow-buffer/src/bigint/mod.rs b/arrow-buffer/src/bigint/mod.rs
index fe07745399..d064663bf6 100644
--- a/arrow-buffer/src/bigint/mod.rs
+++ b/arrow-buffer/src/bigint/mod.rs
@@ -659,6 +659,30 @@ macro_rules! derive_op {
self.$wrapping(rhs)
}
}
+
+ impl<'a> std::ops::$t<i256> for &'a i256 {
+ type Output = i256;
+
+ fn $op(self, rhs: i256) -> Self::Output {
+ (*self).$op(rhs)
+ }
+ }
+
+ impl<'a> std::ops::$t<&'a i256> for i256 {
+ type Output = i256;
+
+ fn $op(self, rhs: &'a i256) -> Self::Output {
+ self.$op(*rhs)
+ }
+ }
+
+ impl<'a, 'b> std::ops::$t<&'b i256> for &'a i256 {
+ type Output = i256;
+
+ fn $op(self, rhs: &'b i256) -> Self::Output {
+ (*self).$op(*rhs)
+ }
+ }
};
}
@@ -1194,4 +1218,57 @@ mod tests {
assert_eq!(i256::from_string(case), expected)
}
}
+
+ #[allow(clippy::op_ref)]
+ fn test_reference_op(il: i256, ir: i256) {
+ let r1 = il + ir;
+ let r2 = &il + ir;
+ let r3 = il + &ir;
+ let r4 = &il + &ir;
+ assert_eq!(r1, r2);
+ assert_eq!(r1, r3);
+ assert_eq!(r1, r4);
+
+ let r1 = il - ir;
+ let r2 = &il - ir;
+ let r3 = il - &ir;
+ let r4 = &il - &ir;
+ assert_eq!(r1, r2);
+ assert_eq!(r1, r3);
+ assert_eq!(r1, r4);
+
+ let r1 = il * ir;
+ let r2 = &il * ir;
+ let r3 = il * &ir;
+ let r4 = &il * &ir;
+ assert_eq!(r1, r2);
+ assert_eq!(r1, r3);
+ assert_eq!(r1, r4);
+
+ let r1 = il / ir;
+ let r2 = &il / ir;
+ let r3 = il / &ir;
+ let r4 = &il / &ir;
+ assert_eq!(r1, r2);
+ assert_eq!(r1, r3);
+ assert_eq!(r1, r4);
+ }
+
+ #[test]
+ fn test_i256_reference_op() {
+ let candidates = [
+ i256::ONE,
+ i256::MINUS_ONE,
+ i256::from_i128(2),
+ i256::from_i128(-2),
+ i256::from_i128(3),
+ i256::from_i128(-3),
+ ];
+
+ for il in candidates {
+ for ir in candidates {
+ test_reference_op(il, ir)
+ }
+ }
+ }
}