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 is a builtin implementation
of ModularInteger based on the Montgomery form.
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
An integer represented in Montgomery form, it implements ModularInteger interface and it’s generally more efficient than the vanilla integer in modular operations.
A double width integer type based on the largest built-in integer (u128). It’s used to support double-width operations on u128.
Traits
Provides a utility function to convert signed integers into unsigned modular form
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.
Type Definitions
Alias of the builtin integer type with max width