num-traits icon indicating copy to clipboard operation
num-traits copied to clipboard

Modular arithmetic

Open Armavica opened this issue 4 years ago • 2 comments

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.

Armavica avatar Mar 22 '21 11:03 Armavica

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?

cuviper avatar Apr 10 '21 00:04 cuviper

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.

cmpute avatar Feb 12 '22 17:02 cmpute