Struct num_modular::Normalized2by1Divisor
source · pub struct Normalized2by1Divisor<T> { /* private fields */ }
Expand description
Divide a DoubleWord by a prearranged divisor.
Assumes quotient fits in a Word.
Möller, Granlund, “Improved division by invariant integers”, Algorithm 4.
Implementations§
source§impl Normalized2by1Divisor<u8>
impl Normalized2by1Divisor<u8>
sourcepub const fn invert_word(divisor: u8) -> u8
pub const fn invert_word(divisor: u8) -> u8
Calculate the inverse m > 0 of a normalized divisor (fit in a word), such that
(m + B) * divisor = B^2 - k for some 1 <= k <= divisor
sourcepub const fn new(divisor: u8) -> Self
pub const fn new(divisor: u8) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
sourcepub const fn div_rem_1by1(&self, a: u8) -> (u8, u8)
pub const fn div_rem_1by1(&self, a: u8) -> (u8, u8)
Returns (a / divisor, a % divisor)
sourcepub const fn div_rem_2by1(&self, a: u16) -> (u8, u8)
pub const fn div_rem_2by1(&self, a: u16) -> (u8, u8)
Returns (a / divisor, a % divisor) The result must fit in a single word.
source§impl Normalized2by1Divisor<u16>
impl Normalized2by1Divisor<u16>
sourcepub const fn invert_word(divisor: u16) -> u16
pub const fn invert_word(divisor: u16) -> u16
Calculate the inverse m > 0 of a normalized divisor (fit in a word), such that
(m + B) * divisor = B^2 - k for some 1 <= k <= divisor
sourcepub const fn new(divisor: u16) -> Self
pub const fn new(divisor: u16) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
sourcepub const fn div_rem_1by1(&self, a: u16) -> (u16, u16)
pub const fn div_rem_1by1(&self, a: u16) -> (u16, u16)
Returns (a / divisor, a % divisor)
sourcepub const fn div_rem_2by1(&self, a: u32) -> (u16, u16)
pub const fn div_rem_2by1(&self, a: u32) -> (u16, u16)
Returns (a / divisor, a % divisor) The result must fit in a single word.
source§impl Normalized2by1Divisor<u32>
impl Normalized2by1Divisor<u32>
sourcepub const fn invert_word(divisor: u32) -> u32
pub const fn invert_word(divisor: u32) -> u32
Calculate the inverse m > 0 of a normalized divisor (fit in a word), such that
(m + B) * divisor = B^2 - k for some 1 <= k <= divisor
sourcepub const fn new(divisor: u32) -> Self
pub const fn new(divisor: u32) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
sourcepub const fn div_rem_1by1(&self, a: u32) -> (u32, u32)
pub const fn div_rem_1by1(&self, a: u32) -> (u32, u32)
Returns (a / divisor, a % divisor)
sourcepub const fn div_rem_2by1(&self, a: u64) -> (u32, u32)
pub const fn div_rem_2by1(&self, a: u64) -> (u32, u32)
Returns (a / divisor, a % divisor) The result must fit in a single word.
source§impl Normalized2by1Divisor<u64>
impl Normalized2by1Divisor<u64>
sourcepub const fn invert_word(divisor: u64) -> u64
pub const fn invert_word(divisor: u64) -> u64
Calculate the inverse m > 0 of a normalized divisor (fit in a word), such that
(m + B) * divisor = B^2 - k for some 1 <= k <= divisor
sourcepub const fn new(divisor: u64) -> Self
pub const fn new(divisor: u64) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
sourcepub const fn div_rem_1by1(&self, a: u64) -> (u64, u64)
pub const fn div_rem_1by1(&self, a: u64) -> (u64, u64)
Returns (a / divisor, a % divisor)
sourcepub const fn div_rem_2by1(&self, a: u128) -> (u64, u64)
pub const fn div_rem_2by1(&self, a: u128) -> (u64, u64)
Returns (a / divisor, a % divisor) The result must fit in a single word.
source§impl Normalized2by1Divisor<usize>
impl Normalized2by1Divisor<usize>
sourcepub const fn invert_word(divisor: usize) -> usize
pub const fn invert_word(divisor: usize) -> usize
Calculate the inverse m > 0 of a normalized divisor (fit in a word), such that
(m + B) * divisor = B^2 - k for some 1 <= k <= divisor
sourcepub const fn new(divisor: usize) -> Self
pub const fn new(divisor: usize) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
sourcepub const fn div_rem_1by1(&self, a: usize) -> (usize, usize)
pub const fn div_rem_1by1(&self, a: usize) -> (usize, usize)
Returns (a / divisor, a % divisor)
sourcepub const fn div_rem_2by1(&self, a: u64) -> (usize, usize)
pub const fn div_rem_2by1(&self, a: u64) -> (usize, usize)
Returns (a / divisor, a % divisor) The result must fit in a single word.
Trait Implementations§
source§impl<T: Clone> Clone for Normalized2by1Divisor<T>
impl<T: Clone> Clone for Normalized2by1Divisor<T>
source§fn clone(&self) -> Normalized2by1Divisor<T>
fn clone(&self) -> Normalized2by1Divisor<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for Normalized2by1Divisor<T>
impl<T: Debug> Debug for Normalized2by1Divisor<T>
source§impl<T: PartialEq> PartialEq<Normalized2by1Divisor<T>> for Normalized2by1Divisor<T>
impl<T: PartialEq> PartialEq<Normalized2by1Divisor<T>> for Normalized2by1Divisor<T>
source§fn eq(&self, other: &Normalized2by1Divisor<T>) -> bool
fn eq(&self, other: &Normalized2by1Divisor<T>) -> bool
self
and other
values to be equal, and is used
by ==
.