Skip to main content

WrappingDiv

Trait WrappingDiv 

Source
pub trait WrappingDiv: Sized + Div<Self> {
    // Required method
    fn wrapping_div(self, v: Self) -> <Self as Div<Self>>::Output;
}
Expand description

Performs division that wraps around on overflow.

Required Methods§

Source

fn wrapping_div(self, v: Self) -> <Self as Div<Self>>::Output

Wrapping (modular) division. Computes self / other, wrapping around at the boundary of the type.

The only case where such wrapping can occur is when one divides MIN / -1 on a signed type; this is equivalent to -MIN, a positive value that is too large to represent in the type. For unsigned types this is a normal division and can never wrap.

§Panics

Panics if other is zero.

use const_num_traits::WrappingDiv;

assert_eq!(WrappingDiv::wrapping_div(100i8, 10), 10);
assert_eq!(WrappingDiv::wrapping_div(i8::MIN, -1), i8::MIN); // wrapped!

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl WrappingDiv for i8

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for i16

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for i32

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for i64

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for i128

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for isize

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for u8

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for u16

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for u32

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for u64

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for u128

Source§

fn wrapping_div(self, v: Self) -> Self

Source§

impl WrappingDiv for usize

Source§

fn wrapping_div(self, v: Self) -> Self

Implementors§