Crates.io | modicum |
lib.rs | modicum |
version | 0.1.0 |
source | src |
created_at | 2024-04-20 10:21:14.157078 |
updated_at | 2024-04-20 10:21:14.157078 |
description | Modular arithemtic library in pure Rust |
homepage | |
repository | https://github.com/teial/modicum |
max_upload_size | |
id | 1214489 |
size | 17,166 |
This library provides a set of traits and implementations for modular arithmetic in pure Rust. It is designed to be flexible and easy to use, with a focus on performance. The library is designed to be used in a variety of contexts, including cryptography, error detection and correction, and other applications where modular arithmetic is useful.
num_traits
crateAdd this to your Cargo.toml
:
[dependencies]
modular_arithmetic = "0.1"
use modular_arithmetic::{ModAdd, ModMul, ModPow};
fn main() {
let a = 5i32;
let b = 7i32;
let m = 11u32;
let sum = a.mod_add(b, m);
let difference = a.mod_sub(b, m);
let product = a.mod_mul(b, m);
let quotient = a.mod_div(b, m);
let power = a.mod_pow(b, m);
println!("{} + {} mod {} = {}", a, b, m, sum);
println!("{} - {} mod {} = {}", a, b, m, difference);
println!("{} * {} mod {} = {}", a, b, m, product);
println!("{} / {} mod {} = {}", a, b, m, quotient);
println!("{} ^ {} mod {} = {}", a, b, m, power);
}