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