modicum 0.1.0

Modular arithemtic library in pure Rust
Documentation
  • Coverage
  • 100%
    28 out of 28 items documented1 out of 16 items with examples
  • Size
  • Source code size: 17.92 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.05 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • teial/modicum
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • teial

A modular arithmetic library in pure Rust

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.

Features

  • Modular arithmetic traits for addition, subtraction, multiplication, division, and exponentiation
  • Implementations for all types supported by num_traits crate

Limitations

  • The library relies on blanket implementation to work for all integers and possbile big integers as well. This may lead to name conflicts if you use this library with other libraries that also implement the same traits for the same types.
  • The operands must be of the same signed type. It is possbile that in future versions this restriction will be lifted.

Usage

Add this to your Cargo.toml:

[dependencies]
modular_arithmetic = "0.1"

Example

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);
}