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

source

pub const fn new(d: i16) -> DivisorI16

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::DivisorI16;

let d = DivisorI16::new(-21);
source

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

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

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

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

source§

fn clone(&self) -> DivisorI16

Returns a copy 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 DivisorI16

source§

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

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

impl Div<DivisorI16> for i16

§

type Output = i16

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl DivAssign<DivisorI16> for i16

source§

fn div_assign(&mut self, rhs: DivisorI16)

Performs the /= operation. Read more
source§

impl Hash for DivisorI16

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 DivisorI16

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rem<DivisorI16> for i16

§

type Output = i16

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

impl RemAssign<DivisorI16> for i16

source§

fn rem_assign(&mut self, rhs: DivisorI16)

Performs the %= operation. Read more
source§

impl Copy for DivisorI16

source§

impl Eq for DivisorI16

source§

impl StructuralEq for DivisorI16

source§

impl StructuralPartialEq for DivisorI16

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> 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>,

§

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>,

§

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.