DivisorI8

Struct DivisorI8 

Source
pub struct DivisorI8 { /* private fields */ }
Expand description

Faster divisor for division and modulo operations by 8-bit signed integer values.

Implementations§

Source§

impl DivisorI8

Source

pub const fn new(d: i8) -> DivisorI8

Creates a divisor which can be used for faster computation of division and modulo by d.

§Panics

Panics if d equals zero.

§Examples
use quickdiv::DivisorI8;

let d = DivisorI8::new(-21);
Source

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);
Source

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));
Source

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);
Source

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 Clone for DivisorI8

Source§

fn clone(&self) -> DivisorI8

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DivisorI8

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<DivisorI8> for i8

Source§

type Output = i8

The resulting type after applying the / operator.
Source§

fn div(self, rhs: DivisorI8) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign<DivisorI8> for i8

Source§

fn div_assign(&mut self, rhs: DivisorI8)

Performs the /= operation. Read more
Source§

impl Hash for DivisorI8

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DivisorI8

Source§

fn eq(&self, other: &DivisorI8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Rem<DivisorI8> for i8

Source§

type Output = i8

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: DivisorI8) -> Self::Output

Performs the % operation. Read more
Source§

impl RemAssign<DivisorI8> for i8

Source§

fn rem_assign(&mut self, rhs: DivisorI8)

Performs the %= operation. Read more
Source§

impl Copy for DivisorI8

Source§

impl Eq for DivisorI8

Source§

impl StructuralPartialEq for DivisorI8

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.