Trait num_traits::ops::checked::CheckedRem [−][src]
pub trait CheckedRem: Sized + Rem<Self, Output = Self> { fn checked_rem(&self, v: &Self) -> Option<Self>; }
Performs an integral remainder that returns None
instead of panicking on division by zero and
instead of wrapping around on underflow and overflow.
Required Methods
fn checked_rem(&self, v: &Self) -> Option<Self>
Finds the remainder of dividing two numbers, checking for underflow, overflow and division
by zero. If any of that happens, None
is returned.
Examples
use num_traits::CheckedRem; use std::i32::MIN; assert_eq!(CheckedRem::checked_rem(&10, &7), Some(3)); assert_eq!(CheckedRem::checked_rem(&10, &-7), Some(3)); assert_eq!(CheckedRem::checked_rem(&-10, &7), Some(-3)); assert_eq!(CheckedRem::checked_rem(&-10, &-7), Some(-3)); assert_eq!(CheckedRem::checked_rem(&10, &0), None); assert_eq!(CheckedRem::checked_rem(&MIN, &1), Some(0)); assert_eq!(CheckedRem::checked_rem(&MIN, &-1), None);
Implementors
impl CheckedRem for u8
impl CheckedRem for u16
impl CheckedRem for u32
impl CheckedRem for u64
impl CheckedRem for usize
impl CheckedRem for u128
impl CheckedRem for i8
impl CheckedRem for i16
impl CheckedRem for i32
impl CheckedRem for i64
impl CheckedRem for isize
impl CheckedRem for i128