Trait num_traits::ops::checked::CheckedRem
source · [−]pub trait CheckedRem: Sized + Rem<Self, Output = Self> {
fn checked_rem(&self, v: &Self) -> Option<Self>;
}
Expand description
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>
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);