viirya commented on code in PR #3040:
URL: https://github.com/apache/arrow-rs/pull/3040#discussion_r1016030872
##########
arrow-buffer/src/bigint.rs:
##########
@@ -478,6 +480,44 @@ define_as_primitive!(i16);
define_as_primitive!(i32);
define_as_primitive!(i64);
+impl ToPrimitive for i256 {
+ fn to_i64(&self) -> Option<i64> {
+ let as_i128 = self.low as i128;
+
+ let high_negative = self.high < 0;
+ let low_negative = as_i128 < 0;
+ let high_valid = self.high == -1 || self.high == 0;
+
+ if high_negative == low_negative && high_valid {
+ let (low_bytes, high_bytes) =
split_array(u128::to_le_bytes(self.low));
+ let high = i64::from_le_bytes(high_bytes);
+ let low = i64::from_le_bytes(low_bytes);
+
+ let high_negative = high < 0;
+ let low_negative = low < 0;
+ let high_valid = self.high == -1 || self.high == 0;
+
+ (high_negative == low_negative && high_valid).then_some(low)
Review Comment:
I tried simply calling `this.low.to_i64()`, but it cannot pass
```
let a = i256::from_i128(i64::MIN as i128);
assert_eq!(a.to_i64().unwrap(), i64::MIN);
```
--
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]