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