pub trait CheckedRem: 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

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

Implementations on Foreign Types

Implementors