num-traits
num-traits copied to clipboard
Modular arithmetic
Hello, Modular arithmetic being a common mathematical and computational concept, would it make sense to add support for it to this library? I was thinking that implementing traits such as
trait CheckedAddMod {
fn checked_add_mod(&self, v: &Self, m: &Self) -> Option<Self>;
}
representing the checked result of the operation (self + v) % m and similar, would make easier and less verbose the writing of these programs.
I think there are a lot of API possibilities to explore here, which makes me hesitate to add it to the conservatively-stable API of num-traits. There are a few crates that look relevant in searching for "modular" on crates.io, or maybe you'd like to start your own?
In case someone is interested, I have created two traits in my num-modular crate for modular arithmetics, namely ModularCoreOps and ModularOps. They are already implemented for several primitive types.