mbutrovich commented on code in PR #11425:
URL: https://github.com/apache/arrow-rs/pull/11425#discussion_r4221437242
##########
arrow-buffer/src/bigint/mod.rs:
##########
@@ -1621,6 +1671,71 @@ mod tests {
}
}
+ fn test_div_rem(n: i256, d: i256) {
+ let bn = BigInt::from_signed_bytes_le(&n.to_le_bytes());
+ let bd = BigInt::from_signed_bytes_le(&d.to_le_bytes());
+
+ // BigInt produces an integer over i256::MAX for i256::MIN / -1
+ let (q, overflow) = i256::from_bigint_with_overflow(bn.clone() /
bd.clone());
+ let (r, _) = i256::from_bigint_with_overflow(bn % bd);
+
+ assert_eq!(n.wrapping_div_rem(d), (q, r), "{n} / {d}");
+ assert_eq!(
+ n.checked_div_rem(d),
+ (!overflow).then_some((q, r)),
+ "{n} / {d}"
+ );
+ }
+
+ #[test]
+ #[cfg_attr(miri, ignore)] // Takes too long
+ fn test_div_rem_powers_of_ten() {
+ let dividends = [
+ i256::ZERO,
+ i256::ONE,
+ i256::MIN,
+ i256::MIN + i256::ONE,
Review Comment:
> nit: `i256::MIN + i256::ONE` is `-i256::MAX`, so with the four sign
combinations below it produces exactly the same `(n, d)` pairs as `i256::MAX`
and could be dropped.
Removed, thanks.
--
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]