neilconway opened a new pull request, #10857: URL: https://github.com/apache/arrow-rs/pull/10857
# Which issue does this PR close? - Closes #10855. # Rationale for this change `ToPrimitive::to_i64` for `i256` re-tested the already-validated top 128 bits instead of bits 64..127, so any value whose two 64-bit halves agree in sign was truncated to its low 64 bits. This resulted in incorrect results when casting Decimal256 to a signed integer type. Fix it by rewriting `i256::to_i64` in terms of `i256::to_i128`, which was already correct. Also rewrite `i256::to_u64` in a similar manner, for consistency. Benchmarking confirms that this approach yields ~equivalent performance to the previous implementation, but removes redundancy and fixes the bug. # What changes are included in this PR? * Implement `to_i64` and `to_u64` in terms of `i256::to_i128` * Add tests, both for `ToPrimitive` and casting-level behavior # Are these changes tested? Yes, new tests added. # Are there any user-facing changes? No, aside from fixing incorrect behavior. -- 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]
