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