use-modular 0.0.5

Small modular arithmetic primitives for RustUse
Documentation
  • Coverage
  • 100%
    21 out of 21 items documented1 out of 17 items with examples
  • Size
  • Source code size: 15.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 410.06 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 23s Average build duration of successful builds.
  • all releases: 43s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • RustUse/use-math
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • CloudBranch

use-modular

Install

[dependencies]
use-modular = "0.0.5"

What belongs here

use-modular owns small modular arithmetic operations over primitive signed integers. It keeps normalization, addition, subtraction, multiplication, exponentiation, inverses, and congruence checks explicit while always returning residues normalized to 0..modulus.

Invalid moduli are handled conservatively: functions return None when modulus <= 0, and congruence checks return false.

Neighboring crates

Crate Responsibility
use-modular Modular arithmetic operations and congruence checks
use-integer Integer classification and integer-specific descriptive helpers
use-number Broader number abstractions and shared numeric vocabulary
use-prime Primality, sieves, prime generation, and factorization
use-algebra Algebraic structures and law checking over caller-supplied ops
use-combinatorics Counting helpers that may consume modular arithmetic
use-cryptography Future protocol and cryptographic constructions built on modularity

use-modular intentionally does not define primality testing, factorization, ring traits, cryptographic protocols, or large arbitrary- precision integer types.

Examples

Normalize and combine residues

use use_modular::{mod_add, mod_mul, mod_sub};

assert_eq!(mod_add(4, 3, 5), Some(2));
assert_eq!(mod_sub(2, 4, 5), Some(3));
assert_eq!(mod_mul(4, 4, 5), Some(1));

Exponentiation and inverse

use use_modular::{mod_inverse, mod_pow};

assert_eq!(mod_pow(2, 10, 1_000), Some(24));
assert_eq!(mod_inverse(3, 11), Some(4));

Congruence

use use_modular::is_congruent;

assert!(is_congruent(17, 5, 12));
assert!(!is_congruent(17, 6, 12));

Status

use-modular is a concrete pre-1.0 crate in the RustUse math workspace. The API stays explicit and dependency-free so adjacent integer, number, algebra, combinatorics, and future cryptography crates can share one small modular arithmetic vocabulary.