neilconway opened a new issue, #10855:
URL: https://github.com/apache/arrow-rs/issues/10855
### Describe the bug
`ToPrimitive::to_i64` for i256 returns the low 64 bits of some values that
do not fit in i64; this is reached by `cast` from `Decimal256` to signed
integers, yielding incorrect results.
### To Reproduce
```rust
use arrow_array::{cast::AsArray, types::Int64Type, Decimal256Array};
use arrow_buffer::i256;
use arrow_cast::{cast_with_options, CastOptions};
use arrow_schema::DataType;
use num_traits::ToPrimitive;
// 2^64 + 5 = 18446744073709551621, which does not fit in i64
let v = i256::from_i128((1i128 << 64) + 5);
v.to_i64(); // Some(5) — expected None
let arr = Decimal256Array::from(vec![v])
.with_precision_and_scale(76, 0)
.unwrap();
let strict = CastOptions { safe: false, ..Default::default() };
let out = cast_with_options(&arr, &DataType::Int64, &strict).unwrap();
out.as_primitive::<Int64Type>().value(0); // 5 — expected an error (safe
mode gives 5 too, not null)
```
### Expected behavior
_No response_
### Additional context
_No response_
--
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]