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