mbutrovich commented on code in PR #11369:
URL: https://github.com/apache/arrow-rs/pull/11369#discussion_r4225259093
##########
arrow-cast/src/cast/decimal.rs:
##########
@@ -783,11 +784,8 @@ where
if array.is_null(i) {
value_builder.append_null();
} else {
- let v = array
- .value(i)
- .div_checked(div)
- .ok()
- .and_then(<T::Native as
NumCast>::from::<D::Native>);
+ let v = array.value(i).div_wrapping(div);
Review Comment:
> it would be nice to add a comment explaining that (`// can never overflow
b/c it is calculated from power of 10` etc
What do you think about writing it once where each divisor is computed,
instead of at each `div_wrapping` call? That's `div` in
[`cast_decimal_to_integer`](https://github.com/apache/arrow-rs/blob/d7c0ebdd2717ec31eacd67909771132e6ab9e865/arrow-cast/src/cast/decimal.rs#L731-L739)
and `scale_factor` in
[`cast_integer_to_decimal`](https://github.com/apache/arrow-rs/blob/d7c0ebdd2717ec31eacd67909771132e6ab9e865/arrow-cast/src/cast/mod.rs#L435-L437).
`div_checked` fails only for a zero divisor or `MIN / -1`, so something like
this would cover both:
```rust
// A power of ten is at least 1, so `div_wrapping` by it can't divide by
zero or
// overflow, and returns the same result as `div_checked`.
```
--
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]