You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "neilconway (via GitHub)" <gi...@apache.org> on 2026/08/26 13:19:33 UTC

[I] Casting decimal256 -> signed int returns wrong values [arrow-rs]

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: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Casting decimal256 -> signed int returns wrong values [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey closed issue #10855: Casting decimal256 -> signed int returns wrong values
URL: https://github.com/apache/arrow-rs/issues/10855


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Casting decimal256 -> signed int returns wrong values [arrow-rs]

Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on issue #10855:
URL: https://github.com/apache/arrow-rs/issues/10855#issuecomment-5425903703

   take


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org