Struct quickdiv::DivisorI32
source · pub struct DivisorI32 { /* private fields */ }
Expand description
Faster divisor for division and modulo operations by 32-bit signed integer values.
Implementations§
source§impl DivisorI32
impl DivisorI32
sourcepub const fn new(d: i32) -> DivisorI32
pub const fn new(d: i32) -> DivisorI32
sourcepub const fn get(&self) -> i32
pub const fn get(&self) -> i32
Returns the value that was used to construct this divisor as a primitive type.
Examples
use quickdiv::DivisorI32;
let d = DivisorI32::new(-15);
assert_eq!(d.get(), -15);
sourcepub const fn divides(&self, n: i32) -> bool
pub const fn divides(&self, n: i32) -> bool
Returns true
if n
is divisible by self
.
We take 0
to be divisible by all non-zero numbers.
Examples
use quickdiv::DivisorI32;
let d = DivisorI32::new(-9);
assert!(d.divides(27));
sourcepub const fn rem_of(&self, n: i32) -> i32
pub const fn rem_of(&self, n: i32) -> i32
Returns the remainder of dividing n
by self
.
Examples
use quickdiv::DivisorI32;
let d = DivisorI32::new(21);
let rem = d.rem_of(-30);
assert_eq!(rem, -9);
sourcepub const fn div_of(&self, n: i32) -> i32
pub const fn div_of(&self, n: i32) -> i32
Returns the result of dividing n
by self
.
This will perform a wrapping division, i.e.
DivisorI32::new(-1).div_of(i32::MIN)
will always silently return
i32::MIN
no matter whether the program was compiled with overflow-checks
turned off or not.
Examples
use quickdiv::DivisorI32;
let d = DivisorI32::new(13);
let div = d.div_of(-30);
assert_eq!(div, -2);
Trait Implementations§
source§impl Clone for DivisorI32
impl Clone for DivisorI32
source§fn clone(&self) -> DivisorI32
fn clone(&self) -> DivisorI32
Returns a copy 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 DivisorI32
impl Debug for DivisorI32
source§impl Div<DivisorI32> for i32
impl Div<DivisorI32> for i32
source§impl DivAssign<DivisorI32> for i32
impl DivAssign<DivisorI32> for i32
source§fn div_assign(&mut self, rhs: DivisorI32)
fn div_assign(&mut self, rhs: DivisorI32)
Performs the
/=
operation. Read moresource§impl Hash for DivisorI32
impl Hash for DivisorI32
source§impl PartialEq for DivisorI32
impl PartialEq for DivisorI32
source§fn eq(&self, other: &DivisorI32) -> bool
fn eq(&self, other: &DivisorI32) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Rem<DivisorI32> for i32
impl Rem<DivisorI32> for i32
source§impl RemAssign<DivisorI32> for i32
impl RemAssign<DivisorI32> for i32
source§fn rem_assign(&mut self, rhs: DivisorI32)
fn rem_assign(&mut self, rhs: DivisorI32)
Performs the
%=
operation. Read moreimpl Copy for DivisorI32
impl Eq for DivisorI32
impl StructuralEq for DivisorI32
impl StructuralPartialEq for DivisorI32
Auto Trait Implementations§
impl RefUnwindSafe for DivisorI32
impl Send for DivisorI32
impl Sync for DivisorI32
impl Unpin for DivisorI32
impl UnwindSafe for DivisorI32
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