Struct dashu_int::modular::ModuloRing
source · pub struct ModuloRing(_);
Expand description
A ring of integers modulo a positive integer.
Examples
let ring = ModuloRing::new(UBig::from(100u8));
assert_eq!(ring.modulus(), UBig::from(100u8));
Implementations§
source§impl ModuloRing
impl ModuloRing
sourcepub fn modulus(&self) -> UBig
pub fn modulus(&self) -> UBig
The ring modulus.
Note that there is overhead for retrieving the original modulus.
Examples
let ring = ModuloRing::new(UBig::from(100u8));
assert_eq!(ring.modulus(), UBig::from(100u8));
sourcepub fn convert<T: IntoModulo>(&self, x: T) -> Modulo<'_>
pub fn convert<T: IntoModulo>(&self, x: T) -> Modulo<'_>
Create an element of the ring from another type.
Examples
let ring = ModuloRing::new(UBig::from(100u8));
let x = ring.convert(-1234);
let y = ring.convert(UBig::from(3366u32));
assert!(x == y);
source§impl ModuloRing
impl ModuloRing
sourcepub fn new(n: UBig) -> ModuloRing
pub fn new(n: UBig) -> ModuloRing
Create a new ring of integers modulo n
.
For two Modulo numbers to be compatible,
they must come from the same ModuloRing.
Two different ModuloRings are not compatible even if
they have the same modulus n
.
Examples
let ring = ModuloRing::new(UBig::from(100u8));
assert_eq!(ring.modulus(), UBig::from(100u8));
Panics
Panics if n
is zero.
Trait Implementations§
source§impl Binary for ModuloRing
impl Binary for ModuloRing
source§impl Debug for ModuloRing
impl Debug for ModuloRing
source§impl Display for ModuloRing
impl Display for ModuloRing
source§impl LowerHex for ModuloRing
impl LowerHex for ModuloRing
source§impl Octal for ModuloRing
impl Octal for ModuloRing
source§impl PartialEq<ModuloRing> for ModuloRing
impl PartialEq<ModuloRing> for ModuloRing
Equality is identity: two rings are not equal even if they have the same modulus.