mbutrovich commented on PR #12232: URL: https://github.com/apache/arrow-rs/pull/12232#issuecomment-6928477833
I wrote a property for these divisors in [arrow-pbt](https://github.com/mbutrovich/arrow-pbt) (mbutrovich/arrow-pbt#1) and ran it against this PR at 3b3e722d5e. It passed seeds 1 to 18 at 10,000 cases each, with no discards. The [property](https://github.com/mbutrovich/arrow-pbt/blob/111762cedbd2ab66b0e73fac7a9bf531438b179b/src/numeric.rs#L1275-L1338) checks all six divisor types against truncated `BigInt` division wrapped to the type, so its oracle shares no code with `i256` division. `new` must return `None` only for 0, `wrapping_div_rem` must wrap only `MIN / -1`, and `checked_div_rem` must return `None` only there. For `DivisorI128` and `DivisorI256` it also checks both rustdoc claims about values that fit the next narrower type: the narrower divisor gives the same results except for -1, and a divisor too wide for that type gives a quotient of 0 and the value as the remainder, except for `MIN / 2^(N - 1)`. The [strategy](https://github.com/mbutrovich/arrow-pbt/blob/111762cedbd2ab66b0e73fac7a9bf531438b179b/src/cases.rs#L1178-L1237) draws divisors and dividends from 0, 1, -1, the limits of the type and of each narrower width, values within one of a power of two or ten, values that fit a narrower width, and values of any bit length. A quarter of the dividends are within one of a multiple of the divisor. Over the run, `DivisorI256::new` returned 6,800 `PowerOfTwo` and 23,286 `AddIndicator` divisors, and `DivisorI128::new` 11,545 and 36,645, counting the narrower divisors that the `DivisorI256` check builds. `MIN / -1` came up 128 times for `i128` and 95 for `i256`, and the narrower type's `MIN / 2^(N - 1)` 96 and 77 times. Each of four deliberate breaks of the oracle (floor division, `checked_div_rem` never returning `None`, no wrap of `MIN / -1`, and no `MIN / 2^(N - 1)` exception) failed within 22 cases. To rerun it, check out the `arrow-rs-12232` branch of arrow-pbt, whose `Cargo.toml` points at this PR, and run: ```sh cargo run -q -- run divisor 1-18 10000 ``` -- 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]
