rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
699 stars 131 forks source link

Add trait for wrapping_div and wrapping_rem #238

Open lukyxu opened 2 years ago

lukyxu commented 2 years ago

There exist traits for wrapping_add, wrapping_sub, wrapping_mul, wrapping_shl, wrapping_shr and wrapping_neg. Is there a reason why there isn't a trait for wrapping div and wrapping rem?

cuviper commented 2 years ago

No particular reason, just that nobody has wanted them yet.

I'm not sure it's very useful to have these in generic contexts -- the only input that actually wraps is signed MIN / -1. Division by zero still panics, at least. But if you have a use case, I wouldn't mind a pull request for new traits.