rust-num / num-integer

Integer trait and functions for Rust
Apache License 2.0
180 stars 48 forks source link

Add checked_* for div and mod functions #57

Open JayXon opened 11 months ago

JayXon commented 11 months ago

It's very easy to implement the check wrong, most people only check if denominator is 0, but not i32::MIN / -1.

cuviper commented 10 months ago

There are already traits for this: https://docs.rs/num-traits/latest/num_traits/ops/checked/index.html

But if you're asking for this on Integer, I don't think there's any compatible way to add these as extra methods.

JayXon commented 10 months ago

Sorry I should've been more clear, I was talking about functions like div_floor, div_mod_floor, mod_floor I don't see a trait for checked variants of these