pub struct DivisorIsize { /* private fields */ }Expand description
Faster divisor for division and modulo operations by pointer-sized signed integer values.
Implementations§
Source§impl DivisorIsize
impl DivisorIsize
Sourcepub const fn new(d: isize) -> DivisorIsize
pub const fn new(d: isize) -> DivisorIsize
Sourcepub const fn get(&self) -> isize
pub const fn get(&self) -> isize
Returns the value that was used to construct this divisor as a primitive type.
§Examples
use quickdiv::DivisorIsize;
let d = DivisorIsize::new(-15);
assert_eq!(d.get(), -15);Sourcepub const fn divides(&self, n: isize) -> bool
pub const fn divides(&self, n: isize) -> bool
Returns true if n is divisible by self.
We take 0 to be divisible by all non-zero numbers.
§Examples
use quickdiv::DivisorIsize;
let d = DivisorIsize::new(-9);
assert!(d.divides(27));Sourcepub const fn rem_of(&self, n: isize) -> isize
pub const fn rem_of(&self, n: isize) -> isize
Returns the remainder of dividing n by self.
§Examples
use quickdiv::DivisorIsize;
let d = DivisorIsize::new(21);
let rem = d.rem_of(-30);
assert_eq!(rem, -9);Sourcepub const fn div_of(&self, n: isize) -> isize
pub const fn div_of(&self, n: isize) -> isize
Returns the result of dividing n by self.
This will perform a wrapping division, i.e.
DivisorIsize::new(-1).div_of(isize::MIN)
will always silently return
isize::MIN
no matter whether the program was compiled with overflow-checks turned off or not.
§Examples
use quickdiv::DivisorIsize;
let d = DivisorIsize::new(13);
let div = d.div_of(-30);
assert_eq!(div, -2);Trait Implementations§
Source§impl Clone for DivisorIsize
impl Clone for DivisorIsize
Source§fn clone(&self) -> DivisorIsize
fn clone(&self) -> DivisorIsize
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DivisorIsize
impl Debug for DivisorIsize
Source§impl Div<DivisorIsize> for isize
impl Div<DivisorIsize> for isize
Source§impl DivAssign<DivisorIsize> for isize
impl DivAssign<DivisorIsize> for isize
Source§fn div_assign(&mut self, rhs: DivisorIsize)
fn div_assign(&mut self, rhs: DivisorIsize)
Performs the
/= operation. Read moreSource§impl Hash for DivisorIsize
impl Hash for DivisorIsize
Source§impl PartialEq for DivisorIsize
impl PartialEq for DivisorIsize
Source§impl Rem<DivisorIsize> for isize
impl Rem<DivisorIsize> for isize
Source§impl RemAssign<DivisorIsize> for isize
impl RemAssign<DivisorIsize> for isize
Source§fn rem_assign(&mut self, rhs: DivisorIsize)
fn rem_assign(&mut self, rhs: DivisorIsize)
Performs the
%= operation. Read moreimpl Copy for DivisorIsize
impl Eq for DivisorIsize
impl StructuralPartialEq for DivisorIsize
Auto Trait Implementations§
impl Freeze for DivisorIsize
impl RefUnwindSafe for DivisorIsize
impl Send for DivisorIsize
impl Sync for DivisorIsize
impl Unpin for DivisorIsize
impl UnwindSafe for DivisorIsize
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more