Crate num_modular
source · [−]Expand description
This crate provides efficient Modular arithmetic operations for various integer types,
including primitive integers and num-bigint
. The latter option is enabled optionally.
To achieve fast modular arithmetics, convert integers to any ModularInteger implementation
use static new()
or associated ModularInteger::new(). MontgomeryInt and MontgomeryBigint
are two builtin implementation based on the Montgomery form. The former one is for stack
allocated integer (like primitive types) and the latter one is for heap allocated integers (like num-bigint::BigUint
)
Example code:
use num_modular::{ModularCoreOps, ModularInteger, MontgomeryInt};
// directly using methods in ModularCoreOps
let (x, y, m) = (12u8, 13u8, 5u8);
assert_eq!(x.mulm(y, &m), x * y % m);
// convert integers into ModularInteger
let mx = MontgomeryInt::new(x, m);
let my = mx.new(y); // faster than static new()
assert_eq!((mx * my).residue(), x * y % m);
Structs
A big integer represented in Montgomery form, it implements ModularInteger interface and it’s generally more efficient than the vanilla integer in modular operations.
An integer represented in Montgomery form, it implements ModularInteger interface and it’s generally more efficient than the vanilla integer in modular operations.
Traits
This trait describes core modular arithmetic operations
Represents an number defined in a modulo ring ℤ/nℤ
This trait describes modular arithmetic operations
Operations of a integer represented in Montgomery form. This data type can be used in place of a normal integer with regard to modular arithmetics.