Trait num::traits::CheckedDivExperimental
[-]
[+]
[src]
pub trait CheckedDiv: Div<Self, Self> { fn checked_div(&self, v: &Self) -> Option<Self>; }
Performs division that returns None
instead of panicking on division by zero and instead of
wrapping around on underflow and overflow.
Required Methods
fn checked_div(&self, v: &Self) -> Option<Self>
Divides two numbers, checking for underflow, overflow and division by zero. If any of that
happens, None
is returned.
Example
extern crate num; fn main() { use num::CheckedDiv; assert_eq!((-127i8).checked_div(&-1), Some(127)); assert_eq!((-128i8).checked_div(&-1), None); assert_eq!((1i8).checked_div(&0), None); }use num::CheckedDiv; assert_eq!((-127i8).checked_div(&-1), Some(127)); assert_eq!((-128i8).checked_div(&-1), None); assert_eq!((1i8).checked_div(&0), None);
Implementors
impl CheckedDiv for BigUint
impl CheckedDiv for BigInt
impl CheckedDiv for int
impl CheckedDiv for i8
impl CheckedDiv for i16
impl CheckedDiv for i32
impl CheckedDiv for i64
impl CheckedDiv for uint
impl CheckedDiv for u8
impl CheckedDiv for u16
impl CheckedDiv for u32
impl CheckedDiv for u64