theirix commented on code in PR #10088:
URL: https://github.com/apache/arrow-rs/pull/10088#discussion_r3448240375
##########
arrow-buffer/src/bigint/mod.rs:
##########
@@ -1085,6 +1102,58 @@ impl WrappingNeg for i256 {
}
}
+// num_traits saturating implementations
+
+impl SaturatingAdd for i256 {
+ fn saturating_add(&self, v: &Self) -> Self {
+ self.checked_add(v).unwrap_or_else(|| {
+ if v.is_negative() {
+ i256::MIN
+ } else {
+ i256::MAX
+ }
+ })
+ }
+}
+
+impl SaturatingSub for i256 {
+ fn saturating_sub(&self, v: &Self) -> Self {
+ self.checked_sub(v).unwrap_or_else(|| {
+ if v.is_negative() {
+ i256::MAX
+ } else {
+ i256::MIN
+ }
+ })
+ }
+}
+
+impl SaturatingMul for i256 {
+ fn saturating_mul(&self, v: &Self) -> Self {
+ self.checked_mul(v).unwrap_or_else(|| {
+ if v.is_negative() {
+ i256::MIN
+ } else {
Review Comment:
Makes sense, updated the tests to catch it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]